<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>SDL_gfx: I:/Sources/sdlgfx/SDL_gfxPrimitives.c Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">SDL_gfx
   &#160;<span id="projectnumber">2.0.25</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.8.0 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">I:/Sources/sdlgfx/SDL_gfxPrimitives.c</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_s_d_l__gfx_primitives_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* </span>
<a name="l00002"></a>00002 <span class="comment"></span>
<a name="l00003"></a>00003 <span class="comment">SDL_gfxPrimitives.c: graphics primitives for SDL surfaces</span>
<a name="l00004"></a>00004 <span class="comment"></span>
<a name="l00005"></a>00005 <span class="comment">Copyright (C) 2001-2012  Andreas Schiffler</span>
<a name="l00006"></a>00006 <span class="comment"></span>
<a name="l00007"></a>00007 <span class="comment">This software is provided &#39;as-is&#39;, without any express or implied</span>
<a name="l00008"></a>00008 <span class="comment">warranty. In no event will the authors be held liable for any damages</span>
<a name="l00009"></a>00009 <span class="comment">arising from the use of this software.</span>
<a name="l00010"></a>00010 <span class="comment"></span>
<a name="l00011"></a>00011 <span class="comment">Permission is granted to anyone to use this software for any purpose,</span>
<a name="l00012"></a>00012 <span class="comment">including commercial applications, and to alter it and redistribute it</span>
<a name="l00013"></a>00013 <span class="comment">freely, subject to the following restrictions:</span>
<a name="l00014"></a>00014 <span class="comment"></span>
<a name="l00015"></a>00015 <span class="comment">1. The origin of this software must not be misrepresented; you must not</span>
<a name="l00016"></a>00016 <span class="comment">claim that you wrote the original software. If you use this software</span>
<a name="l00017"></a>00017 <span class="comment">in a product, an acknowledgment in the product documentation would be</span>
<a name="l00018"></a>00018 <span class="comment">appreciated but is not required.</span>
<a name="l00019"></a>00019 <span class="comment"></span>
<a name="l00020"></a>00020 <span class="comment">2. Altered source versions must be plainly marked as such, and must not be</span>
<a name="l00021"></a>00021 <span class="comment">misrepresented as being the original software.</span>
<a name="l00022"></a>00022 <span class="comment"></span>
<a name="l00023"></a>00023 <span class="comment">3. This notice may not be removed or altered from any source</span>
<a name="l00024"></a>00024 <span class="comment">distribution.</span>
<a name="l00025"></a>00025 <span class="comment"></span>
<a name="l00026"></a>00026 <span class="comment">Andreas Schiffler -- aschiffler at ferzkopp dot net</span>
<a name="l00027"></a>00027 <span class="comment"></span>
<a name="l00028"></a>00028 <span class="comment">*/</span>
<a name="l00029"></a>00029 
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;math.h&gt;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00034"></a>00034 
<a name="l00035"></a>00035 <span class="preprocessor">#include &quot;<a class="code" href="_s_d_l__gfx_primitives_8h.html">SDL_gfxPrimitives.h</a>&quot;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include &quot;<a class="code" href="_s_d_l__rotozoom_8h.html">SDL_rotozoom.h</a>&quot;</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include &quot;<a class="code" href="_s_d_l__gfx_primitives__font_8h.html">SDL_gfxPrimitives_font.h</a>&quot;</span>
<a name="l00038"></a>00038 <span class="preprocessor">#include &quot;<a class="code" href="_s_d_l__gfx_blit_func_8h.html">SDL_gfxBlitFunc.h</a>&quot;</span>
<a name="l00039"></a>00039 
<a name="l00040"></a>00040 <span class="comment">/* -===================- */</span>
<a name="l00041"></a>00041 
<a name="l00042"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#aa992e3a7310145e9f9c36edee5795996">00042</a> <span class="preprocessor">#define DEFAULT_ALPHA_PIXEL_ROUTINE</span>
<a name="l00043"></a>00043 <span class="preprocessor"></span><span class="preprocessor">#undef EXPERIMENTAL_ALPHA_PIXEL_ROUTINE</span>
<a name="l00044"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#aa24430b32607587eae143f31c1ad14dd">00044</a> <span class="preprocessor"></span><span class="preprocessor">#define ALPHA_PIXEL_ADDITIVE_BLEND</span>
<a name="l00045"></a>00045 <span class="preprocessor"></span>
<a name="l00046"></a>00046 <span class="comment">/* ---- Structures */</span>
<a name="l00047"></a>00047 
<a name="l00051"></a><a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html">00051</a> <span class="keyword">typedef</span> <span class="keyword">struct </span>{
<a name="l00052"></a><a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a48ddc054175e25d435c217ad4639c3a1">00052</a>         Sint16 x, <a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a48ddc054175e25d435c217ad4639c3a1">y</a>;
<a name="l00053"></a><a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#ace147c79e29f2efd14e5744efcb976af">00053</a>         <span class="keywordtype">int</span> dx, dy, s1, s2, <a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#ace147c79e29f2efd14e5744efcb976af">swapdir</a>, error;
<a name="l00054"></a><a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a92fcd448f278df155fd5472527a6dc47">00054</a>         Uint32 <a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a92fcd448f278df155fd5472527a6dc47">count</a>;
<a name="l00055"></a>00055 } <a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html" title="The structure passed to the internal Bresenham iterator.">SDL_gfxBresenhamIterator</a>;
<a name="l00056"></a>00056 
<a name="l00060"></a><a class="code" href="struct_s_d_l__gfx_murphy_iterator.html">00060</a> <span class="keyword">typedef</span> <span class="keyword">struct </span>{
<a name="l00061"></a><a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#afd133e412238ed9f1e3ba52397115e8d">00061</a>         Uint32 <a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#afd133e412238ed9f1e3ba52397115e8d">color</a>;
<a name="l00062"></a><a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af6547de04c77c00ed2d4597dd48ca807">00062</a>         SDL_Surface *<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af6547de04c77c00ed2d4597dd48ca807">dst</a>;
<a name="l00063"></a><a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac8859e8c1ce357c4c8b37bbb1936ba1c">00063</a>         <span class="keywordtype">int</span> u, <a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac8859e8c1ce357c4c8b37bbb1936ba1c">v</a>;               <span class="comment">/* delta x , delta y */</span>
<a name="l00064"></a><a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af59597daf52972ab61551495c3d7e6cd">00064</a>         <span class="keywordtype">int</span> ku, kt, <a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af59597daf52972ab61551495c3d7e6cd">kv</a>, kd;     <span class="comment">/* loop constants */</span>
<a name="l00065"></a><a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ab9894ea9f5570af0e7fa86e61a3bb60b">00065</a>         <span class="keywordtype">int</span> <a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ab9894ea9f5570af0e7fa86e61a3bb60b">oct2</a>;
<a name="l00066"></a><a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac65502ab7d0d8cbf739c6e06c35d8edb">00066</a>         <span class="keywordtype">int</span> <a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac65502ab7d0d8cbf739c6e06c35d8edb">quad4</a>;
<a name="l00067"></a><a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a4c3e88fc7abb5715d04e28d96a154e5f">00067</a>         Sint16 last1x, last1y, last2x, last2y, first1x, first1y, first2x, first2y, tempx, <a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a4c3e88fc7abb5715d04e28d96a154e5f">tempy</a>;
<a name="l00068"></a>00068 } <a class="code" href="struct_s_d_l__gfx_murphy_iterator.html" title="The structure passed to the internal Murphy iterator.">SDL_gfxMurphyIterator</a>;
<a name="l00069"></a>00069 
<a name="l00070"></a>00070 <span class="comment">/* ----- Defines for pixel clipping tests */</span>
<a name="l00071"></a>00071 
<a name="l00072"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#adeb851ac45f74ddec914212dd3297433">00072</a> <span class="preprocessor">#define clip_xmin(surface) surface-&gt;clip_rect.x</span>
<a name="l00073"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#add68946c6ecf1a5b8935309d30b85cab">00073</a> <span class="preprocessor"></span><span class="preprocessor">#define clip_xmax(surface) surface-&gt;clip_rect.x+surface-&gt;clip_rect.w-1</span>
<a name="l00074"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#afc94a05f9b044427c21a77cc468aa5d4">00074</a> <span class="preprocessor"></span><span class="preprocessor">#define clip_ymin(surface) surface-&gt;clip_rect.y</span>
<a name="l00075"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#a2f0d9475a02c76e14c8bcba854ac7067">00075</a> <span class="preprocessor"></span><span class="preprocessor">#define clip_ymax(surface) surface-&gt;clip_rect.y+surface-&gt;clip_rect.h-1</span>
<a name="l00076"></a>00076 <span class="preprocessor"></span>
<a name="l00087"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742">00087</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Uint32 color)
<a name="l00088"></a>00088 {
<a name="l00089"></a>00089         <span class="keywordtype">int</span> bpp;
<a name="l00090"></a>00090         Uint8 *p;
<a name="l00091"></a>00091 
<a name="l00092"></a>00092         <span class="comment">/*</span>
<a name="l00093"></a>00093 <span class="comment">        * Honor clipping setup at pixel level </span>
<a name="l00094"></a>00094 <span class="comment">        */</span>
<a name="l00095"></a>00095         <span class="keywordflow">if</span> ((x &gt;= <a class="code" href="_s_d_l__gfx_primitives_8c.html#adeb851ac45f74ddec914212dd3297433">clip_xmin</a>(dst)) &amp;&amp; (x &lt;= <a class="code" href="_s_d_l__gfx_primitives_8c.html#add68946c6ecf1a5b8935309d30b85cab">clip_xmax</a>(dst)) &amp;&amp; (y &gt;= <a class="code" href="_s_d_l__gfx_primitives_8c.html#afc94a05f9b044427c21a77cc468aa5d4">clip_ymin</a>(dst)) &amp;&amp; (y &lt;= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a2f0d9475a02c76e14c8bcba854ac7067">clip_ymax</a>(dst))) {
<a name="l00096"></a>00096 
<a name="l00097"></a>00097                 <span class="comment">/*</span>
<a name="l00098"></a>00098 <span class="comment">                * Get destination format </span>
<a name="l00099"></a>00099 <span class="comment">                */</span>
<a name="l00100"></a>00100                 bpp = dst-&gt;format-&gt;BytesPerPixel;
<a name="l00101"></a>00101                 p = (Uint8 *) dst-&gt;pixels + y * dst-&gt;pitch + x * bpp;
<a name="l00102"></a>00102                 switch (bpp) {
<a name="l00103"></a>00103                 <span class="keywordflow">case</span> 1:
<a name="l00104"></a>00104                         *p = color;
<a name="l00105"></a>00105                         <span class="keywordflow">break</span>;
<a name="l00106"></a>00106                 <span class="keywordflow">case</span> 2:
<a name="l00107"></a>00107                         *(Uint16 *) p = color;
<a name="l00108"></a>00108                         <span class="keywordflow">break</span>;
<a name="l00109"></a>00109                 <span class="keywordflow">case</span> 3:
<a name="l00110"></a>00110                         <span class="keywordflow">if</span> (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
<a name="l00111"></a>00111                                 p[0] = (color &gt;&gt; 16) &amp; 0xff;
<a name="l00112"></a>00112                                 p[1] = (color &gt;&gt; 8) &amp; 0xff;
<a name="l00113"></a>00113                                 p[2] = color &amp; 0xff;
<a name="l00114"></a>00114                         } <span class="keywordflow">else</span> {
<a name="l00115"></a>00115                                 p[0] = color &amp; 0xff;
<a name="l00116"></a>00116                                 p[1] = (color &gt;&gt; 8) &amp; 0xff;
<a name="l00117"></a>00117                                 p[2] = (color &gt;&gt; 16) &amp; 0xff;
<a name="l00118"></a>00118                         }
<a name="l00119"></a>00119                         <span class="keywordflow">break</span>;
<a name="l00120"></a>00120                 <span class="keywordflow">case</span> 4:
<a name="l00121"></a>00121                         *(Uint32 *) p = color;
<a name="l00122"></a>00122                         <span class="keywordflow">break</span>;
<a name="l00123"></a>00123                 }                       <span class="comment">/* switch */</span>
<a name="l00124"></a>00124 
<a name="l00125"></a>00125 
<a name="l00126"></a>00126         }
<a name="l00127"></a>00127 
<a name="l00128"></a>00128         <span class="keywordflow">return</span> (0);
<a name="l00129"></a>00129 }
<a name="l00130"></a>00130 
<a name="l00144"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#add868bff0c4cb75012a0407af6b64f03">00144</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#add868bff0c4cb75012a0407af6b64f03" title="Internal pixel drawing - fast, no blending, no locking, no clipping.">fastPixelColorNolockNoclip</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Uint32 color)
<a name="l00145"></a>00145 {
<a name="l00146"></a>00146         <span class="keywordtype">int</span> bpp;
<a name="l00147"></a>00147         Uint8 *p;
<a name="l00148"></a>00148 
<a name="l00149"></a>00149         <span class="comment">/*</span>
<a name="l00150"></a>00150 <span class="comment">        * Get destination format </span>
<a name="l00151"></a>00151 <span class="comment">        */</span>
<a name="l00152"></a>00152         bpp = dst-&gt;format-&gt;BytesPerPixel;
<a name="l00153"></a>00153         p = (Uint8 *) dst-&gt;pixels + y * dst-&gt;pitch + x * bpp;
<a name="l00154"></a>00154         switch (bpp) {
<a name="l00155"></a>00155         <span class="keywordflow">case</span> 1:
<a name="l00156"></a>00156                 *p = color;
<a name="l00157"></a>00157                 <span class="keywordflow">break</span>;
<a name="l00158"></a>00158         <span class="keywordflow">case</span> 2:
<a name="l00159"></a>00159                 *(Uint16 *) p = color;
<a name="l00160"></a>00160                 <span class="keywordflow">break</span>;
<a name="l00161"></a>00161         <span class="keywordflow">case</span> 3:
<a name="l00162"></a>00162                 <span class="keywordflow">if</span> (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
<a name="l00163"></a>00163                         p[0] = (color &gt;&gt; 16) &amp; 0xff;
<a name="l00164"></a>00164                         p[1] = (color &gt;&gt; 8) &amp; 0xff;
<a name="l00165"></a>00165                         p[2] = color &amp; 0xff;
<a name="l00166"></a>00166                 } <span class="keywordflow">else</span> {
<a name="l00167"></a>00167                         p[0] = color &amp; 0xff;
<a name="l00168"></a>00168                         p[1] = (color &gt;&gt; 8) &amp; 0xff;
<a name="l00169"></a>00169                         p[2] = (color &gt;&gt; 16) &amp; 0xff;
<a name="l00170"></a>00170                 }
<a name="l00171"></a>00171                 <span class="keywordflow">break</span>;
<a name="l00172"></a>00172         <span class="keywordflow">case</span> 4:
<a name="l00173"></a>00173                 *(Uint32 *) p = color;
<a name="l00174"></a>00174                 <span class="keywordflow">break</span>;
<a name="l00175"></a>00175         }                               <span class="comment">/* switch */</span>
<a name="l00176"></a>00176 
<a name="l00177"></a>00177         <span class="keywordflow">return</span> (0);
<a name="l00178"></a>00178 }
<a name="l00179"></a>00179 
<a name="l00190"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#abeed0e873efdf3aec8c6c86188d36f89">00190</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#abeed0e873efdf3aec8c6c86188d36f89" title="Internal pixel drawing - fast, no blending, locking, clipping.">fastPixelColor</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Uint32 color)
<a name="l00191"></a>00191 {
<a name="l00192"></a>00192         <span class="keywordtype">int</span> result;
<a name="l00193"></a>00193 
<a name="l00194"></a>00194         <span class="comment">/*</span>
<a name="l00195"></a>00195 <span class="comment">        * Lock the surface </span>
<a name="l00196"></a>00196 <span class="comment">        */</span>
<a name="l00197"></a>00197         <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l00198"></a>00198                 <span class="keywordflow">if</span> (SDL_LockSurface(dst) &lt; 0) {
<a name="l00199"></a>00199                         <span class="keywordflow">return</span> (-1);
<a name="l00200"></a>00200                 }
<a name="l00201"></a>00201         }
<a name="l00202"></a>00202 
<a name="l00203"></a>00203         result = <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, x, y, color);
<a name="l00204"></a>00204 
<a name="l00205"></a>00205         <span class="comment">/*</span>
<a name="l00206"></a>00206 <span class="comment">        * Unlock surface </span>
<a name="l00207"></a>00207 <span class="comment">        */</span>
<a name="l00208"></a>00208         <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l00209"></a>00209                 SDL_UnlockSurface(dst);
<a name="l00210"></a>00210         }
<a name="l00211"></a>00211 
<a name="l00212"></a>00212         <span class="keywordflow">return</span> (result);
<a name="l00213"></a>00213 }
<a name="l00214"></a>00214 
<a name="l00228"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#a9874fabafdc422223323751671bca7c0">00228</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a9874fabafdc422223323751671bca7c0" title="Internal pixel drawing - fast, no blending, locking, RGB input.">fastPixelRGBA</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l00229"></a>00229 {
<a name="l00230"></a>00230         Uint32 color;
<a name="l00231"></a>00231 
<a name="l00232"></a>00232         <span class="comment">/*</span>
<a name="l00233"></a>00233 <span class="comment">        * Setup color </span>
<a name="l00234"></a>00234 <span class="comment">        */</span>
<a name="l00235"></a>00235         color = SDL_MapRGBA(dst-&gt;format, r, g, b, a);
<a name="l00236"></a>00236 
<a name="l00237"></a>00237         <span class="comment">/*</span>
<a name="l00238"></a>00238 <span class="comment">        * Draw </span>
<a name="l00239"></a>00239 <span class="comment">        */</span>
<a name="l00240"></a>00240         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#abeed0e873efdf3aec8c6c86188d36f89" title="Internal pixel drawing - fast, no blending, locking, clipping.">fastPixelColor</a>(dst, x, y, color));
<a name="l00241"></a>00241 }
<a name="l00242"></a>00242 
<a name="l00256"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#a64916bb8270e75d936cda816d3694a25">00256</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a64916bb8270e75d936cda816d3694a25" title="Internal pixel drawing - fast, no blending, no locking RGB input.">fastPixelRGBANolock</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l00257"></a>00257 {
<a name="l00258"></a>00258         Uint32 color;
<a name="l00259"></a>00259 
<a name="l00260"></a>00260         <span class="comment">/*</span>
<a name="l00261"></a>00261 <span class="comment">        * Setup color </span>
<a name="l00262"></a>00262 <span class="comment">        */</span>
<a name="l00263"></a>00263         color = SDL_MapRGBA(dst-&gt;format, r, g, b, a);
<a name="l00264"></a>00264 
<a name="l00265"></a>00265         <span class="comment">/*</span>
<a name="l00266"></a>00266 <span class="comment">        * Draw </span>
<a name="l00267"></a>00267 <span class="comment">        */</span>
<a name="l00268"></a>00268         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, x, y, color));
<a name="l00269"></a>00269 }
<a name="l00270"></a>00270 
<a name="l00286"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#ad31779f1ef8bad84496d4c930ec2c208">00286</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#ad31779f1ef8bad84496d4c930ec2c208" title="Internal pixel drawing function with alpha blending where input color in in destination format...">_putPixelAlpha</a>(SDL_Surface *dst, Sint16 x, Sint16 y, Uint32 color, Uint8 alpha)
<a name="l00287"></a>00287 {
<a name="l00288"></a>00288         SDL_PixelFormat *format;
<a name="l00289"></a>00289         Uint32 Rmask, Gmask, Bmask, Amask;
<a name="l00290"></a>00290         Uint32 Rshift, Gshift, Bshift, Ashift;
<a name="l00291"></a>00291         Uint32 sR, sG, sB;
<a name="l00292"></a>00292         Uint32 dR, dG, dB, dA;
<a name="l00293"></a>00293 
<a name="l00294"></a>00294         <span class="keywordflow">if</span> (dst == NULL)
<a name="l00295"></a>00295         {
<a name="l00296"></a>00296                 <span class="keywordflow">return</span> (-1);
<a name="l00297"></a>00297         }
<a name="l00298"></a>00298 
<a name="l00299"></a>00299         <span class="keywordflow">if</span> (x &gt;= <a class="code" href="_s_d_l__gfx_primitives_8c.html#adeb851ac45f74ddec914212dd3297433">clip_xmin</a>(dst) &amp;&amp; x &lt;= <a class="code" href="_s_d_l__gfx_primitives_8c.html#add68946c6ecf1a5b8935309d30b85cab">clip_xmax</a>(dst) &amp;&amp; 
<a name="l00300"></a>00300                 y &gt;= <a class="code" href="_s_d_l__gfx_primitives_8c.html#afc94a05f9b044427c21a77cc468aa5d4">clip_ymin</a>(dst) &amp;&amp; y &lt;= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a2f0d9475a02c76e14c8bcba854ac7067">clip_ymax</a>(dst)) 
<a name="l00301"></a>00301         {
<a name="l00302"></a>00302 
<a name="l00303"></a>00303                 format = dst-&gt;format;
<a name="l00304"></a>00304 
<a name="l00305"></a>00305                 <span class="keywordflow">switch</span> (format-&gt;BytesPerPixel) {
<a name="l00306"></a>00306                 <span class="keywordflow">case</span> 1:
<a name="l00307"></a>00307                         {               <span class="comment">/* Assuming 8-bpp */</span>
<a name="l00308"></a>00308                                 Uint8 *pixel = (Uint8 *) dst-&gt;pixels + y * dst-&gt;pitch + x;
<a name="l00309"></a>00309                                 if (alpha == 255) {
<a name="l00310"></a>00310                                         *pixel = color;
<a name="l00311"></a>00311                                 } <span class="keywordflow">else</span> {
<a name="l00312"></a>00312                                         Uint8 R, G, B;
<a name="l00313"></a>00313                                         SDL_Palette *palette = format-&gt;palette;
<a name="l00314"></a>00314                                         SDL_Color *colors = palette-&gt;colors;
<a name="l00315"></a>00315                                         SDL_Color dColor = colors[*pixel];
<a name="l00316"></a>00316                                         SDL_Color sColor = colors[color];
<a name="l00317"></a>00317                                         dR = dColor.r;
<a name="l00318"></a>00318                                         dG = dColor.g;
<a name="l00319"></a>00319                                         dB = dColor.b;
<a name="l00320"></a>00320                                         sR = sColor.r;
<a name="l00321"></a>00321                                         sG = sColor.g;
<a name="l00322"></a>00322                                         sB = sColor.b;
<a name="l00323"></a>00323 
<a name="l00324"></a>00324                                         R = dR + ((sR - dR) * alpha &gt;&gt; 8);
<a name="l00325"></a>00325                                         G = dG + ((sG - dG) * alpha &gt;&gt; 8);
<a name="l00326"></a>00326                                         B = dB + ((sB - dB) * alpha &gt;&gt; 8);
<a name="l00327"></a>00327 
<a name="l00328"></a>00328                                         *pixel = SDL_MapRGB(format, R, G, B);
<a name="l00329"></a>00329                                 }
<a name="l00330"></a>00330                         }
<a name="l00331"></a>00331                         <span class="keywordflow">break</span>;
<a name="l00332"></a>00332 
<a name="l00333"></a>00333                 <span class="keywordflow">case</span> 2:
<a name="l00334"></a>00334                         {               <span class="comment">/* Probably 15-bpp or 16-bpp */</span>
<a name="l00335"></a>00335                                 Uint16 *pixel = (Uint16 *) dst-&gt;pixels + y * dst-&gt;pitch / 2 + x;
<a name="l00336"></a>00336                                 if (alpha == 255) {
<a name="l00337"></a>00337                                         *pixel = color;
<a name="l00338"></a>00338                                 } <span class="keywordflow">else</span> {
<a name="l00339"></a>00339                                         Uint16 R, G, B, A;
<a name="l00340"></a>00340                                         Uint16 dc = *pixel;
<a name="l00341"></a>00341 
<a name="l00342"></a>00342                                         Rmask = format-&gt;Rmask;
<a name="l00343"></a>00343                                         Gmask = format-&gt;Gmask;
<a name="l00344"></a>00344                                         Bmask = format-&gt;Bmask;
<a name="l00345"></a>00345                                         Amask = format-&gt;Amask;
<a name="l00346"></a>00346 
<a name="l00347"></a>00347                                         dR = (dc &amp; Rmask);
<a name="l00348"></a>00348                                         dG = (dc &amp; Gmask);
<a name="l00349"></a>00349                                         dB = (dc &amp; Bmask);
<a name="l00350"></a>00350 
<a name="l00351"></a>00351                                         R = (dR + (((color &amp; Rmask) - dR) * alpha &gt;&gt; 8)) &amp; Rmask;
<a name="l00352"></a>00352                                         G = (dG + (((color &amp; Gmask) - dG) * alpha &gt;&gt; 8)) &amp; Gmask;
<a name="l00353"></a>00353                                         B = (dB + (((color &amp; Bmask) - dB) * alpha &gt;&gt; 8)) &amp; Bmask;
<a name="l00354"></a>00354                                         *pixel = R | G | B;
<a name="l00355"></a>00355                                         <span class="keywordflow">if</span> (Amask!=0) {
<a name="l00356"></a>00356                                                 dA = (dc &amp; Amask);
<a name="l00357"></a>00357                                                 A = (dA + (((color &amp; Amask) - dA) * alpha &gt;&gt; 8)) &amp; Amask;
<a name="l00358"></a>00358                                                 *pixel |= A;
<a name="l00359"></a>00359                                         }
<a name="l00360"></a>00360                                 }
<a name="l00361"></a>00361                         }
<a name="l00362"></a>00362                         <span class="keywordflow">break</span>;
<a name="l00363"></a>00363 
<a name="l00364"></a>00364                 <span class="keywordflow">case</span> 3: 
<a name="l00365"></a>00365                         {               <span class="comment">/* Slow 24-bpp mode, usually not used */</span>
<a name="l00366"></a>00366                                 Uint8 R, G, B;
<a name="l00367"></a>00367                                 Uint8 Rshift8, Gshift8, Bshift8;
<a name="l00368"></a>00368                                 Uint8 *pixel = (Uint8 *) dst-&gt;pixels + y * dst-&gt;pitch + x * 3;
<a name="l00369"></a>00369 
<a name="l00370"></a>00370                                 Rshift = format-&gt;Rshift;
<a name="l00371"></a>00371                                 Gshift = format-&gt;Gshift;
<a name="l00372"></a>00372                                 Bshift = format-&gt;Bshift;
<a name="l00373"></a>00373 
<a name="l00374"></a>00374                                 Rshift8 = Rshift &gt;&gt; 3;
<a name="l00375"></a>00375                                 Gshift8 = Gshift &gt;&gt; 3;
<a name="l00376"></a>00376                                 Bshift8 = Bshift &gt;&gt; 3;
<a name="l00377"></a>00377 
<a name="l00378"></a>00378                                 sR = (color &gt;&gt; Rshift) &amp; 0xFF;
<a name="l00379"></a>00379                                 sG = (color &gt;&gt; Gshift) &amp; 0xFF;
<a name="l00380"></a>00380                                 sB = (color &gt;&gt; Bshift) &amp; 0xFF;
<a name="l00381"></a>00381 
<a name="l00382"></a>00382                                 <span class="keywordflow">if</span> (alpha == 255) {
<a name="l00383"></a>00383                                         *(pixel + Rshift8) = sR;
<a name="l00384"></a>00384                                         *(pixel + Gshift8) = sG;
<a name="l00385"></a>00385                                         *(pixel + Bshift8) = sB;
<a name="l00386"></a>00386                                 } <span class="keywordflow">else</span> {
<a name="l00387"></a>00387                                         dR = *((pixel) + Rshift8);
<a name="l00388"></a>00388                                         dG = *((pixel) + Gshift8);
<a name="l00389"></a>00389                                         dB = *((pixel) + Bshift8);
<a name="l00390"></a>00390 
<a name="l00391"></a>00391                                         R = dR + ((sR - dR) * alpha &gt;&gt; 8);
<a name="l00392"></a>00392                                         G = dG + ((sG - dG) * alpha &gt;&gt; 8);
<a name="l00393"></a>00393                                         B = dB + ((sB - dB) * alpha &gt;&gt; 8);
<a name="l00394"></a>00394 
<a name="l00395"></a>00395                                         *((pixel) + Rshift8) = R;
<a name="l00396"></a>00396                                         *((pixel) + Gshift8) = G;
<a name="l00397"></a>00397                                         *((pixel) + Bshift8) = B;
<a name="l00398"></a>00398                                 }
<a name="l00399"></a>00399                         }
<a name="l00400"></a>00400                         <span class="keywordflow">break</span>;
<a name="l00401"></a>00401 
<a name="l00402"></a>00402 <span class="preprocessor">#ifdef DEFAULT_ALPHA_PIXEL_ROUTINE</span>
<a name="l00403"></a>00403 <span class="preprocessor"></span>
<a name="l00404"></a>00404                 <span class="keywordflow">case</span> 4:
<a name="l00405"></a>00405                         {               <span class="comment">/* Probably :-) 32-bpp */</span>
<a name="l00406"></a>00406                                 Uint32 R, G, B, A;
<a name="l00407"></a>00407                                 Uint32 *pixel = (Uint32 *) dst-&gt;pixels + y * dst-&gt;pitch / 4 + x;
<a name="l00408"></a>00408                                 if (alpha == 255) {
<a name="l00409"></a>00409                                         *pixel = color;
<a name="l00410"></a>00410                                 } <span class="keywordflow">else</span> {
<a name="l00411"></a>00411                                         Uint32 dc = *pixel;
<a name="l00412"></a>00412 
<a name="l00413"></a>00413                                         Rmask = format-&gt;Rmask;
<a name="l00414"></a>00414                                         Gmask = format-&gt;Gmask;
<a name="l00415"></a>00415                                         Bmask = format-&gt;Bmask;
<a name="l00416"></a>00416                                         Amask = format-&gt;Amask;
<a name="l00417"></a>00417 
<a name="l00418"></a>00418                                         Rshift = format-&gt;Rshift;
<a name="l00419"></a>00419                                         Gshift = format-&gt;Gshift;
<a name="l00420"></a>00420                                         Bshift = format-&gt;Bshift;
<a name="l00421"></a>00421                                         Ashift = format-&gt;Ashift;
<a name="l00422"></a>00422 
<a name="l00423"></a>00423                                         dR = (dc &amp; Rmask) &gt;&gt; Rshift;
<a name="l00424"></a>00424                                         dG = (dc &amp; Gmask) &gt;&gt; Gshift;
<a name="l00425"></a>00425                                         dB = (dc &amp; Bmask) &gt;&gt; Bshift;
<a name="l00426"></a>00426 
<a name="l00427"></a>00427 
<a name="l00428"></a>00428                                         R = ((dR + ((((color &amp; Rmask) &gt;&gt; Rshift) - dR) * alpha &gt;&gt; 8)) &lt;&lt; Rshift) &amp; Rmask;
<a name="l00429"></a>00429                                         G = ((dG + ((((color &amp; Gmask) &gt;&gt; Gshift) - dG) * alpha &gt;&gt; 8)) &lt;&lt; Gshift) &amp; Gmask;
<a name="l00430"></a>00430                                         B = ((dB + ((((color &amp; Bmask) &gt;&gt; Bshift) - dB) * alpha &gt;&gt; 8)) &lt;&lt; Bshift) &amp; Bmask;
<a name="l00431"></a>00431                                         *pixel = R | G | B;
<a name="l00432"></a>00432                                         <span class="keywordflow">if</span> (Amask!=0) {
<a name="l00433"></a>00433                                                 dA = (dc &amp; Amask) &gt;&gt; Ashift;
<a name="l00434"></a>00434 
<a name="l00435"></a>00435 <span class="preprocessor">#ifdef ALPHA_PIXEL_ADDITIVE_BLEND</span>
<a name="l00436"></a>00436 <span class="preprocessor"></span>                                                A = (dA | <a class="code" href="_s_d_l__gfx_blit_func_8c.html#a6d0c17342154e14322a281603960691a" title="Alpha adjustment table for custom blitter.">GFX_ALPHA_ADJUST_ARRAY</a>[alpha &amp; 255]) &lt;&lt; Ashift; <span class="comment">// make destination less transparent...</span>
<a name="l00437"></a>00437 <span class="preprocessor">#else</span>
<a name="l00438"></a>00438 <span class="preprocessor"></span>                                                A = ((dA + ((((color &amp; Amask) &gt;&gt; Ashift) - dA) * alpha &gt;&gt; 8)) &lt;&lt; Ashift) &amp; Amask;
<a name="l00439"></a>00439 <span class="preprocessor">#endif</span>
<a name="l00440"></a>00440 <span class="preprocessor"></span>                                                *pixel |= A;
<a name="l00441"></a>00441                                         }
<a name="l00442"></a>00442                                 }
<a name="l00443"></a>00443                         }
<a name="l00444"></a>00444                         <span class="keywordflow">break</span>;
<a name="l00445"></a>00445 <span class="preprocessor">#endif</span>
<a name="l00446"></a>00446 <span class="preprocessor"></span>
<a name="l00447"></a>00447 <span class="preprocessor">#ifdef EXPERIMENTAL_ALPHA_PIXEL_ROUTINE</span>
<a name="l00448"></a>00448 <span class="preprocessor"></span>
<a name="l00449"></a>00449                 <span class="keywordflow">case</span> 4:{                <span class="comment">/* Probably :-) 32-bpp */</span>
<a name="l00450"></a>00450                         <span class="keywordflow">if</span> (alpha == 255) {
<a name="l00451"></a>00451                                 *((Uint32 *) dst-&gt;pixels + y * dst-&gt;pitch / 4 + x) = color;
<a name="l00452"></a>00452                         } <span class="keywordflow">else</span> {
<a name="l00453"></a>00453                                 Uint32 *pixel = (Uint32 *) dst-&gt;pixels + y * dst-&gt;pitch / 4 + x;
<a name="l00454"></a>00454                                 Uint32 dR, dG, dB, dA;
<a name="l00455"></a>00455                                 Uint32 dc = *pixel;
<a name="l00456"></a>00456 
<a name="l00457"></a>00457                                 Uint32 surfaceAlpha, preMultR, preMultG, preMultB;
<a name="l00458"></a>00458                                 Uint32 aTmp;
<a name="l00459"></a>00459 
<a name="l00460"></a>00460                                 Rmask = format-&gt;Rmask;
<a name="l00461"></a>00461                                 Gmask = format-&gt;Gmask;
<a name="l00462"></a>00462                                 Bmask = format-&gt;Bmask;
<a name="l00463"></a>00463                                 Amask = format-&gt;Amask;
<a name="l00464"></a>00464 
<a name="l00465"></a>00465                                 dR = (color &amp; Rmask);
<a name="l00466"></a>00466                                 dG = (color &amp; Gmask);
<a name="l00467"></a>00467                                 dB = (color &amp; Bmask);
<a name="l00468"></a>00468                                 dA = (color &amp; Amask);
<a name="l00469"></a>00469 
<a name="l00470"></a>00470                                 Rshift = format-&gt;Rshift;
<a name="l00471"></a>00471                                 Gshift = format-&gt;Gshift;
<a name="l00472"></a>00472                                 Bshift = format-&gt;Bshift;
<a name="l00473"></a>00473                                 Ashift = format-&gt;Ashift;
<a name="l00474"></a>00474 
<a name="l00475"></a>00475                                 preMultR = (alpha * (dR &gt;&gt; Rshift));
<a name="l00476"></a>00476                                 preMultG = (alpha * (dG &gt;&gt; Gshift));
<a name="l00477"></a>00477                                 preMultB = (alpha * (dB &gt;&gt; Bshift));
<a name="l00478"></a>00478 
<a name="l00479"></a>00479                                 surfaceAlpha = ((dc &amp; Amask) &gt;&gt; Ashift);
<a name="l00480"></a>00480                                 aTmp = (255 - alpha);
<a name="l00481"></a>00481                                 <span class="keywordflow">if</span> (A = 255 - ((aTmp * (255 - surfaceAlpha)) &gt;&gt; 8 )) {
<a name="l00482"></a>00482                                         aTmp *= surfaceAlpha;
<a name="l00483"></a>00483                                         R = (preMultR + ((aTmp * ((dc &amp; Rmask) &gt;&gt; Rshift)) &gt;&gt; 8)) / A &lt;&lt; Rshift &amp; Rmask;
<a name="l00484"></a>00484                                         G = (preMultG + ((aTmp * ((dc &amp; Gmask) &gt;&gt; Gshift)) &gt;&gt; 8)) / A &lt;&lt; Gshift &amp; Gmask;
<a name="l00485"></a>00485                                         B = (preMultB + ((aTmp * ((dc &amp; Bmask) &gt;&gt; Bshift)) &gt;&gt; 8)) / A &lt;&lt; Bshift &amp; Bmask;
<a name="l00486"></a>00486                                 }
<a name="l00487"></a>00487                                 *pixel = R | G | B | (A &lt;&lt; Ashift &amp; Amask);
<a name="l00488"></a>00488 
<a name="l00489"></a>00489                         }
<a name="l00490"></a>00490                            }
<a name="l00491"></a>00491                            <span class="keywordflow">break</span>;
<a name="l00492"></a>00492 <span class="preprocessor">#endif</span>
<a name="l00493"></a>00493 <span class="preprocessor"></span>                }
<a name="l00494"></a>00494         }
<a name="l00495"></a>00495 
<a name="l00496"></a>00496         <span class="keywordflow">return</span> (0);
<a name="l00497"></a>00497 }
<a name="l00498"></a>00498 
<a name="l00509"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a7fe611dbb029ae70be89d5314c7e023b">00509</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae6f8690e5c5a85d3263c8e16727b34ef" title="Pixel draw with blending enabled if a&lt;255.">pixelColor</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Uint32 color)
<a name="l00510"></a>00510 {
<a name="l00511"></a>00511         Uint8 alpha;
<a name="l00512"></a>00512         Uint32 mcolor;
<a name="l00513"></a>00513         <span class="keywordtype">int</span> result = 0;
<a name="l00514"></a>00514 
<a name="l00515"></a>00515         <span class="comment">/*</span>
<a name="l00516"></a>00516 <span class="comment">        * Lock the surface </span>
<a name="l00517"></a>00517 <span class="comment">        */</span>
<a name="l00518"></a>00518         <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l00519"></a>00519                 <span class="keywordflow">if</span> (SDL_LockSurface(dst) &lt; 0) {
<a name="l00520"></a>00520                         <span class="keywordflow">return</span> (-1);
<a name="l00521"></a>00521                 }
<a name="l00522"></a>00522         }
<a name="l00523"></a>00523 
<a name="l00524"></a>00524         <span class="comment">/*</span>
<a name="l00525"></a>00525 <span class="comment">        * Setup color </span>
<a name="l00526"></a>00526 <span class="comment">        */</span>
<a name="l00527"></a>00527         alpha = color &amp; 0x000000ff;
<a name="l00528"></a>00528         mcolor =
<a name="l00529"></a>00529                 SDL_MapRGBA(dst-&gt;format, (color &amp; 0xff000000) &gt;&gt; 24,
<a name="l00530"></a>00530                 (color &amp; 0x00ff0000) &gt;&gt; 16, (color &amp; 0x0000ff00) &gt;&gt; 8, alpha);
<a name="l00531"></a>00531 
<a name="l00532"></a>00532         <span class="comment">/*</span>
<a name="l00533"></a>00533 <span class="comment">        * Draw </span>
<a name="l00534"></a>00534 <span class="comment">        */</span>
<a name="l00535"></a>00535         result = <a class="code" href="_s_d_l__gfx_primitives_8c.html#ad31779f1ef8bad84496d4c930ec2c208" title="Internal pixel drawing function with alpha blending where input color in in destination format...">_putPixelAlpha</a>(dst, x, y, mcolor, alpha);
<a name="l00536"></a>00536 
<a name="l00537"></a>00537         <span class="comment">/*</span>
<a name="l00538"></a>00538 <span class="comment">        * Unlock the surface </span>
<a name="l00539"></a>00539 <span class="comment">        */</span>
<a name="l00540"></a>00540         <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l00541"></a>00541                 SDL_UnlockSurface(dst);
<a name="l00542"></a>00542         }
<a name="l00543"></a>00543 
<a name="l00544"></a>00544         <span class="keywordflow">return</span> (result);
<a name="l00545"></a>00545 }
<a name="l00546"></a>00546 
<a name="l00557"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0">00557</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Uint32 color)
<a name="l00558"></a>00558 {
<a name="l00559"></a>00559         Uint8 alpha;
<a name="l00560"></a>00560         Uint32 mcolor;
<a name="l00561"></a>00561         <span class="keywordtype">int</span> result = 0;
<a name="l00562"></a>00562 
<a name="l00563"></a>00563         <span class="comment">/*</span>
<a name="l00564"></a>00564 <span class="comment">        * Setup color </span>
<a name="l00565"></a>00565 <span class="comment">        */</span>
<a name="l00566"></a>00566         alpha = color &amp; 0x000000ff;
<a name="l00567"></a>00567         mcolor =
<a name="l00568"></a>00568                 SDL_MapRGBA(dst-&gt;format, (color &amp; 0xff000000) &gt;&gt; 24,
<a name="l00569"></a>00569                 (color &amp; 0x00ff0000) &gt;&gt; 16, (color &amp; 0x0000ff00) &gt;&gt; 8, alpha);
<a name="l00570"></a>00570 
<a name="l00571"></a>00571         <span class="comment">/*</span>
<a name="l00572"></a>00572 <span class="comment">        * Draw </span>
<a name="l00573"></a>00573 <span class="comment">        */</span>
<a name="l00574"></a>00574         result = <a class="code" href="_s_d_l__gfx_primitives_8c.html#ad31779f1ef8bad84496d4c930ec2c208" title="Internal pixel drawing function with alpha blending where input color in in destination format...">_putPixelAlpha</a>(dst, x, y, mcolor, alpha);
<a name="l00575"></a>00575 
<a name="l00576"></a>00576         <span class="keywordflow">return</span> (result);
<a name="l00577"></a>00577 }
<a name="l00578"></a>00578 
<a name="l00579"></a>00579 
<a name="l00595"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#ada8cf05419af4be65d3ea5f7c7384e58">00595</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#ada8cf05419af4be65d3ea5f7c7384e58" title="Internal function to draw filled rectangle with alpha blending.">_filledRectAlpha</a>(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color, Uint8 alpha)
<a name="l00596"></a>00596 {
<a name="l00597"></a>00597         SDL_PixelFormat *format;
<a name="l00598"></a>00598         Uint32 Rmask, Gmask, Bmask, Amask;
<a name="l00599"></a>00599         Uint32 Rshift, Gshift, Bshift, Ashift;
<a name="l00600"></a>00600         Uint32 sR, sG, sB, sA;
<a name="l00601"></a>00601         Uint32 dR, dG, dB, dA;
<a name="l00602"></a>00602         Sint16 x, y;
<a name="l00603"></a>00603 
<a name="l00604"></a>00604         <span class="keywordflow">if</span> (dst == NULL) {
<a name="l00605"></a>00605                 <span class="keywordflow">return</span> (-1);
<a name="l00606"></a>00606         }
<a name="l00607"></a>00607 
<a name="l00608"></a>00608         format = dst-&gt;format;
<a name="l00609"></a>00609         <span class="keywordflow">switch</span> (format-&gt;BytesPerPixel) {
<a name="l00610"></a>00610         <span class="keywordflow">case</span> 1:
<a name="l00611"></a>00611                 {                       <span class="comment">/* Assuming 8-bpp */</span>
<a name="l00612"></a>00612                         Uint8 *row, *pixel;
<a name="l00613"></a>00613                         Uint8 R, G, B;
<a name="l00614"></a>00614                         SDL_Color *colors = format-&gt;palette-&gt;colors;
<a name="l00615"></a>00615                         SDL_Color dColor;
<a name="l00616"></a>00616                         SDL_Color sColor = colors[color];
<a name="l00617"></a>00617                         sR = sColor.r;
<a name="l00618"></a>00618                         sG = sColor.g;
<a name="l00619"></a>00619                         sB = sColor.b;
<a name="l00620"></a>00620 
<a name="l00621"></a>00621                         <span class="keywordflow">for</span> (y = y1; y &lt;= y2; y++) {
<a name="l00622"></a>00622                                 row = (Uint8 *) dst-&gt;pixels + y * dst-&gt;pitch;
<a name="l00623"></a>00623                                 for (x = x1; x &lt;= x2; x++) {
<a name="l00624"></a>00624                                         <span class="keywordflow">if</span> (alpha == 255) {
<a name="l00625"></a>00625                                                 *(row + x) = color;
<a name="l00626"></a>00626                                         } <span class="keywordflow">else</span> {
<a name="l00627"></a>00627                                                 pixel = row + x;
<a name="l00628"></a>00628 
<a name="l00629"></a>00629                                                 dColor = colors[*pixel];
<a name="l00630"></a>00630                                                 dR = dColor.r;
<a name="l00631"></a>00631                                                 dG = dColor.g;
<a name="l00632"></a>00632                                                 dB = dColor.b;
<a name="l00633"></a>00633 
<a name="l00634"></a>00634                                                 R = dR + ((sR - dR) * alpha &gt;&gt; 8);
<a name="l00635"></a>00635                                                 G = dG + ((sG - dG) * alpha &gt;&gt; 8);
<a name="l00636"></a>00636                                                 B = dB + ((sB - dB) * alpha &gt;&gt; 8);
<a name="l00637"></a>00637 
<a name="l00638"></a>00638                                                 *pixel = SDL_MapRGB(format, R, G, B);
<a name="l00639"></a>00639                                         }
<a name="l00640"></a>00640                                 }
<a name="l00641"></a>00641                         }
<a name="l00642"></a>00642                 }
<a name="l00643"></a>00643                 <span class="keywordflow">break</span>;
<a name="l00644"></a>00644 
<a name="l00645"></a>00645         <span class="keywordflow">case</span> 2:
<a name="l00646"></a>00646                 {                       <span class="comment">/* Probably 15-bpp or 16-bpp */</span>
<a name="l00647"></a>00647                         Uint16 *row, *pixel;
<a name="l00648"></a>00648                         Uint16 R, G, B, A;
<a name="l00649"></a>00649                         Uint16 dc;
<a name="l00650"></a>00650                         Rmask = format-&gt;Rmask;
<a name="l00651"></a>00651                         Gmask = format-&gt;Gmask;
<a name="l00652"></a>00652                         Bmask = format-&gt;Bmask;
<a name="l00653"></a>00653                         Amask = format-&gt;Amask;
<a name="l00654"></a>00654 
<a name="l00655"></a>00655                         sR = (color &amp; Rmask); 
<a name="l00656"></a>00656                         sG = (color &amp; Gmask);
<a name="l00657"></a>00657                         sB = (color &amp; Bmask);
<a name="l00658"></a>00658                         sA = (color &amp; Amask);
<a name="l00659"></a>00659 
<a name="l00660"></a>00660                         <span class="keywordflow">for</span> (y = y1; y &lt;= y2; y++) {
<a name="l00661"></a>00661                                 row = (Uint16 *) dst-&gt;pixels + y * dst-&gt;pitch / 2;
<a name="l00662"></a>00662                                 for (x = x1; x &lt;= x2; x++) {
<a name="l00663"></a>00663                                         <span class="keywordflow">if</span> (alpha == 255) {
<a name="l00664"></a>00664                                                 *(row + x) = color;
<a name="l00665"></a>00665                                         } <span class="keywordflow">else</span> {
<a name="l00666"></a>00666                                                 pixel = row + x;
<a name="l00667"></a>00667                                                 dc = *pixel;
<a name="l00668"></a>00668 
<a name="l00669"></a>00669                                                 dR = (dc &amp; Rmask);
<a name="l00670"></a>00670                                                 dG = (dc &amp; Gmask);
<a name="l00671"></a>00671                                                 dB = (dc &amp; Bmask);
<a name="l00672"></a>00672 
<a name="l00673"></a>00673                                                 R = (dR + ((sR - dR) * alpha &gt;&gt; 8)) &amp; Rmask;
<a name="l00674"></a>00674                                                 G = (dG + ((sG - dG) * alpha &gt;&gt; 8)) &amp; Gmask;
<a name="l00675"></a>00675                                                 B = (dB + ((sB - dB) * alpha &gt;&gt; 8)) &amp; Bmask;
<a name="l00676"></a>00676                                                 *pixel = R | G | B;
<a name="l00677"></a>00677                                                 <span class="keywordflow">if</span> (Amask!=0) {
<a name="l00678"></a>00678                                                         dA = (dc &amp; Amask);
<a name="l00679"></a>00679                                                         A = (dA + ((sA - dA) * alpha &gt;&gt; 8)) &amp; Amask;
<a name="l00680"></a>00680                                                         *pixel |= A;
<a name="l00681"></a>00681                                                 } 
<a name="l00682"></a>00682                                         }
<a name="l00683"></a>00683                                 }
<a name="l00684"></a>00684                         }
<a name="l00685"></a>00685                 }
<a name="l00686"></a>00686                 <span class="keywordflow">break</span>;
<a name="l00687"></a>00687 
<a name="l00688"></a>00688         <span class="keywordflow">case</span> 3:
<a name="l00689"></a>00689                 {                       <span class="comment">/* Slow 24-bpp mode, usually not used */</span>
<a name="l00690"></a>00690                         Uint8 *row, *pixel;
<a name="l00691"></a>00691                         Uint8 R, G, B;
<a name="l00692"></a>00692                         Uint8 Rshift8, Gshift8, Bshift8;
<a name="l00693"></a>00693 
<a name="l00694"></a>00694                         Rshift = format-&gt;Rshift;
<a name="l00695"></a>00695                         Gshift = format-&gt;Gshift;
<a name="l00696"></a>00696                         Bshift = format-&gt;Bshift;
<a name="l00697"></a>00697 
<a name="l00698"></a>00698                         Rshift8 = Rshift &gt;&gt; 3;
<a name="l00699"></a>00699                         Gshift8 = Gshift &gt;&gt; 3;
<a name="l00700"></a>00700                         Bshift8 = Bshift &gt;&gt; 3;
<a name="l00701"></a>00701 
<a name="l00702"></a>00702                         sR = (color &gt;&gt; Rshift) &amp; 0xff;
<a name="l00703"></a>00703                         sG = (color &gt;&gt; Gshift) &amp; 0xff;
<a name="l00704"></a>00704                         sB = (color &gt;&gt; Bshift) &amp; 0xff;
<a name="l00705"></a>00705 
<a name="l00706"></a>00706                         <span class="keywordflow">for</span> (y = y1; y &lt;= y2; y++) {
<a name="l00707"></a>00707                                 row = (Uint8 *) dst-&gt;pixels + y * dst-&gt;pitch;
<a name="l00708"></a>00708                                 for (x = x1; x &lt;= x2; x++) {
<a name="l00709"></a>00709                                         pixel = row + x * 3;
<a name="l00710"></a>00710 
<a name="l00711"></a>00711                                         <span class="keywordflow">if</span> (alpha == 255) {
<a name="l00712"></a>00712                                                 *(pixel + Rshift8) = sR;
<a name="l00713"></a>00713                                                 *(pixel + Gshift8) = sG;
<a name="l00714"></a>00714                                                 *(pixel + Bshift8) = sB;
<a name="l00715"></a>00715                                         } <span class="keywordflow">else</span> {
<a name="l00716"></a>00716                                                 dR = *((pixel) + Rshift8);
<a name="l00717"></a>00717                                                 dG = *((pixel) + Gshift8);
<a name="l00718"></a>00718                                                 dB = *((pixel) + Bshift8);
<a name="l00719"></a>00719 
<a name="l00720"></a>00720                                                 R = dR + ((sR - dR) * alpha &gt;&gt; 8);
<a name="l00721"></a>00721                                                 G = dG + ((sG - dG) * alpha &gt;&gt; 8);
<a name="l00722"></a>00722                                                 B = dB + ((sB - dB) * alpha &gt;&gt; 8);
<a name="l00723"></a>00723 
<a name="l00724"></a>00724                                                 *((pixel) + Rshift8) = R;
<a name="l00725"></a>00725                                                 *((pixel) + Gshift8) = G;
<a name="l00726"></a>00726                                                 *((pixel) + Bshift8) = B;
<a name="l00727"></a>00727                                         }
<a name="l00728"></a>00728                                 }
<a name="l00729"></a>00729                         }
<a name="l00730"></a>00730                 }
<a name="l00731"></a>00731                 <span class="keywordflow">break</span>;
<a name="l00732"></a>00732 
<a name="l00733"></a>00733 <span class="preprocessor">#ifdef DEFAULT_ALPHA_PIXEL_ROUTINE</span>
<a name="l00734"></a>00734 <span class="preprocessor"></span>        <span class="keywordflow">case</span> 4:
<a name="l00735"></a>00735                 {                       <span class="comment">/* Probably :-) 32-bpp */</span>
<a name="l00736"></a>00736                         Uint32 *row, *pixel;
<a name="l00737"></a>00737                         Uint32 R, G, B, A;
<a name="l00738"></a>00738                         Uint32 dc;
<a name="l00739"></a>00739                         Rmask = format-&gt;Rmask;
<a name="l00740"></a>00740                         Gmask = format-&gt;Gmask;
<a name="l00741"></a>00741                         Bmask = format-&gt;Bmask;
<a name="l00742"></a>00742                         Amask = format-&gt;Amask;
<a name="l00743"></a>00743 
<a name="l00744"></a>00744                         Rshift = format-&gt;Rshift;
<a name="l00745"></a>00745                         Gshift = format-&gt;Gshift;
<a name="l00746"></a>00746                         Bshift = format-&gt;Bshift;
<a name="l00747"></a>00747                         Ashift = format-&gt;Ashift;
<a name="l00748"></a>00748 
<a name="l00749"></a>00749                         sR = (color &amp; Rmask) &gt;&gt; Rshift;
<a name="l00750"></a>00750                         sG = (color &amp; Gmask) &gt;&gt; Gshift;
<a name="l00751"></a>00751                         sB = (color &amp; Bmask) &gt;&gt; Bshift;
<a name="l00752"></a>00752                         sA = (color &amp; Amask) &gt;&gt; Ashift;
<a name="l00753"></a>00753 
<a name="l00754"></a>00754                         <span class="keywordflow">for</span> (y = y1; y &lt;= y2; y++) {
<a name="l00755"></a>00755                                 row = (Uint32 *) dst-&gt;pixels + y * dst-&gt;pitch / 4;
<a name="l00756"></a>00756                                 for (x = x1; x &lt;= x2; x++) {
<a name="l00757"></a>00757                                         <span class="keywordflow">if</span> (alpha == 255) {
<a name="l00758"></a>00758                                                 *(row + x) = color;
<a name="l00759"></a>00759                                         } <span class="keywordflow">else</span> {
<a name="l00760"></a>00760                                                 pixel = row + x;
<a name="l00761"></a>00761                                                 dc = *pixel;
<a name="l00762"></a>00762 
<a name="l00763"></a>00763                                                 dR = (dc &amp; Rmask) &gt;&gt; Rshift;
<a name="l00764"></a>00764                                                 dG = (dc &amp; Gmask) &gt;&gt; Gshift;
<a name="l00765"></a>00765                                                 dB = (dc &amp; Bmask) &gt;&gt; Bshift;
<a name="l00766"></a>00766 
<a name="l00767"></a>00767                                                 R = ((dR + ((sR - dR) * alpha &gt;&gt; 8)) &lt;&lt; Rshift) &amp; Rmask;
<a name="l00768"></a>00768                                                 G = ((dG + ((sG - dG) * alpha &gt;&gt; 8)) &lt;&lt; Gshift) &amp; Gmask;
<a name="l00769"></a>00769                                                 B = ((dB + ((sB - dB) * alpha &gt;&gt; 8)) &lt;&lt; Bshift) &amp; Bmask;
<a name="l00770"></a>00770                                                 *pixel = R | G | B;
<a name="l00771"></a>00771                                                 <span class="keywordflow">if</span> (Amask!=0) {
<a name="l00772"></a>00772                                                         dA = (dc &amp; Amask) &gt;&gt; Ashift;
<a name="l00773"></a>00773 <span class="preprocessor">#ifdef ALPHA_PIXEL_ADDITIVE_BLEND</span>
<a name="l00774"></a>00774 <span class="preprocessor"></span>                                                        A = (dA | <a class="code" href="_s_d_l__gfx_blit_func_8c.html#a6d0c17342154e14322a281603960691a" title="Alpha adjustment table for custom blitter.">GFX_ALPHA_ADJUST_ARRAY</a>[sA &amp; 255]) &lt;&lt; Ashift; <span class="comment">// make destination less transparent...</span>
<a name="l00775"></a>00775 <span class="preprocessor">#else</span>
<a name="l00776"></a>00776 <span class="preprocessor"></span>                                                        A = ((dA + ((sA - dA) * alpha &gt;&gt; 8)) &lt;&lt; Ashift) &amp; Amask;
<a name="l00777"></a>00777 <span class="preprocessor">#endif</span>
<a name="l00778"></a>00778 <span class="preprocessor"></span>                                                        *pixel |= A;
<a name="l00779"></a>00779                                                 }
<a name="l00780"></a>00780                                         }
<a name="l00781"></a>00781                                 }
<a name="l00782"></a>00782                         }
<a name="l00783"></a>00783                 }
<a name="l00784"></a>00784                 <span class="keywordflow">break</span>;
<a name="l00785"></a>00785 <span class="preprocessor">#endif</span>
<a name="l00786"></a>00786 <span class="preprocessor"></span>
<a name="l00787"></a>00787 <span class="preprocessor">#ifdef EXPERIMENTAL_ALPHA_PIXEL_ROUTINE</span>
<a name="l00788"></a>00788 <span class="preprocessor"></span>        <span class="keywordflow">case</span> 4:{                        <span class="comment">/* Probably :-) 32-bpp */</span>
<a name="l00789"></a>00789                 Uint32 *row, *pixel;
<a name="l00790"></a>00790                 Uint32 dR, dG, dB, dA;
<a name="l00791"></a>00791                 Uint32 dc;
<a name="l00792"></a>00792                 Uint32 surfaceAlpha, preMultR, preMultG, preMultB;
<a name="l00793"></a>00793                 Uint32 aTmp;
<a name="l00794"></a>00794 
<a name="l00795"></a>00795                 Rmask = format-&gt;Rmask;
<a name="l00796"></a>00796                 Gmask = format-&gt;Gmask;
<a name="l00797"></a>00797                 Bmask = format-&gt;Bmask;
<a name="l00798"></a>00798                 Amask = format-&gt;Amask;
<a name="l00799"></a>00799 
<a name="l00800"></a>00800                 dR = (color &amp; Rmask);
<a name="l00801"></a>00801                 dG = (color &amp; Gmask);
<a name="l00802"></a>00802                 dB = (color &amp; Bmask);
<a name="l00803"></a>00803                 dA = (color &amp; Amask);
<a name="l00804"></a>00804 
<a name="l00805"></a>00805                 Rshift = format-&gt;Rshift;
<a name="l00806"></a>00806                 Gshift = format-&gt;Gshift;
<a name="l00807"></a>00807                 Bshift = format-&gt;Bshift;
<a name="l00808"></a>00808                 Ashift = format-&gt;Ashift;
<a name="l00809"></a>00809 
<a name="l00810"></a>00810                 preMultR = (alpha * (dR &gt;&gt; Rshift));
<a name="l00811"></a>00811                 preMultG = (alpha * (dG &gt;&gt; Gshift));
<a name="l00812"></a>00812                 preMultB = (alpha * (dB &gt;&gt; Bshift));
<a name="l00813"></a>00813 
<a name="l00814"></a>00814                 <span class="keywordflow">for</span> (y = y1; y &lt;= y2; y++) {
<a name="l00815"></a>00815                         row = (Uint32 *) dst-&gt;pixels + y * dst-&gt;pitch / 4;
<a name="l00816"></a>00816                         for (x = x1; x &lt;= x2; x++) {
<a name="l00817"></a>00817                                 <span class="keywordflow">if</span> (alpha == 255) {
<a name="l00818"></a>00818                                         *(row + x) = color;
<a name="l00819"></a>00819                                 } <span class="keywordflow">else</span> {
<a name="l00820"></a>00820                                         pixel = row + x;
<a name="l00821"></a>00821                                         dc = *pixel;
<a name="l00822"></a>00822 
<a name="l00823"></a>00823                                         surfaceAlpha = ((dc &amp; Amask) &gt;&gt; Ashift);
<a name="l00824"></a>00824                                         aTmp = (255 - alpha);
<a name="l00825"></a>00825                                         <span class="keywordflow">if</span> (A = 255 - ((aTmp * (255 - surfaceAlpha)) &gt;&gt; 8 )) {
<a name="l00826"></a>00826                                                 aTmp *= surfaceAlpha;
<a name="l00827"></a>00827                                                 R = (preMultR + ((aTmp * ((dc &amp; Rmask) &gt;&gt; Rshift)) &gt;&gt; 8)) / A &lt;&lt; Rshift &amp; Rmask;
<a name="l00828"></a>00828                                                 G = (preMultG + ((aTmp * ((dc &amp; Gmask) &gt;&gt; Gshift)) &gt;&gt; 8)) / A &lt;&lt; Gshift &amp; Gmask;
<a name="l00829"></a>00829                                                 B = (preMultB + ((aTmp * ((dc &amp; Bmask) &gt;&gt; Bshift)) &gt;&gt; 8)) / A &lt;&lt; Bshift &amp; Bmask;
<a name="l00830"></a>00830                                         }
<a name="l00831"></a>00831                                         *pixel = R | G | B | (A &lt;&lt; Ashift &amp; Amask);
<a name="l00832"></a>00832                                 }
<a name="l00833"></a>00833                         }
<a name="l00834"></a>00834                 }
<a name="l00835"></a>00835                    }
<a name="l00836"></a>00836                    <span class="keywordflow">break</span>;
<a name="l00837"></a>00837 <span class="preprocessor">#endif</span>
<a name="l00838"></a>00838 <span class="preprocessor"></span>
<a name="l00839"></a>00839         }
<a name="l00840"></a>00840 
<a name="l00841"></a>00841         <span class="keywordflow">return</span> (0);
<a name="l00842"></a>00842 }
<a name="l00843"></a>00843 
<a name="l00856"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#ace9f2505c12c5dacc778509991cd3716">00856</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#ace9f2505c12c5dacc778509991cd3716" title="Draw filled rectangle of RGBA color with alpha blending.">filledRectAlpha</a>(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color)
<a name="l00857"></a>00857 {
<a name="l00858"></a>00858         Uint8 alpha;
<a name="l00859"></a>00859         Uint32 mcolor;
<a name="l00860"></a>00860         <span class="keywordtype">int</span> result = 0;
<a name="l00861"></a>00861 
<a name="l00862"></a>00862         <span class="comment">/*</span>
<a name="l00863"></a>00863 <span class="comment">        * Lock the surface </span>
<a name="l00864"></a>00864 <span class="comment">        */</span>
<a name="l00865"></a>00865         <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l00866"></a>00866                 <span class="keywordflow">if</span> (SDL_LockSurface(dst) &lt; 0) {
<a name="l00867"></a>00867                         <span class="keywordflow">return</span> (-1);
<a name="l00868"></a>00868                 }
<a name="l00869"></a>00869         }
<a name="l00870"></a>00870 
<a name="l00871"></a>00871         <span class="comment">/*</span>
<a name="l00872"></a>00872 <span class="comment">        * Setup color </span>
<a name="l00873"></a>00873 <span class="comment">        */</span>
<a name="l00874"></a>00874         alpha = color &amp; 0x000000ff;
<a name="l00875"></a>00875         mcolor =
<a name="l00876"></a>00876                 SDL_MapRGBA(dst-&gt;format, (color &amp; 0xff000000) &gt;&gt; 24,
<a name="l00877"></a>00877                 (color &amp; 0x00ff0000) &gt;&gt; 16, (color &amp; 0x0000ff00) &gt;&gt; 8, alpha);
<a name="l00878"></a>00878 
<a name="l00879"></a>00879         <span class="comment">/*</span>
<a name="l00880"></a>00880 <span class="comment">        * Draw </span>
<a name="l00881"></a>00881 <span class="comment">        */</span>
<a name="l00882"></a>00882         result = <a class="code" href="_s_d_l__gfx_primitives_8c.html#ada8cf05419af4be65d3ea5f7c7384e58" title="Internal function to draw filled rectangle with alpha blending.">_filledRectAlpha</a>(dst, x1, y1, x2, y2, mcolor, alpha);
<a name="l00883"></a>00883 
<a name="l00884"></a>00884         <span class="comment">/*</span>
<a name="l00885"></a>00885 <span class="comment">        * Unlock the surface </span>
<a name="l00886"></a>00886 <span class="comment">        */</span>
<a name="l00887"></a>00887         <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l00888"></a>00888                 SDL_UnlockSurface(dst);
<a name="l00889"></a>00889         }
<a name="l00890"></a>00890 
<a name="l00891"></a>00891         <span class="keywordflow">return</span> (result);
<a name="l00892"></a>00892 }
<a name="l00893"></a>00893 
<a name="l00905"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#a9eb9c20c69b527cda814a19212270efa">00905</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a9eb9c20c69b527cda814a19212270efa" title="Internal function to draw horizontal line of RGBA color with alpha blending.">_HLineAlpha</a>(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16 y, Uint32 color)
<a name="l00906"></a>00906 {
<a name="l00907"></a>00907         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ace9f2505c12c5dacc778509991cd3716" title="Draw filled rectangle of RGBA color with alpha blending.">filledRectAlpha</a>(dst, x1, y, x2, y, color));
<a name="l00908"></a>00908 }
<a name="l00909"></a>00909 
<a name="l00921"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#a61dd5e7523ce84fb103da3338acd3a37">00921</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a61dd5e7523ce84fb103da3338acd3a37" title="Internal function to draw vertical line of RGBA color with alpha blending.">_VLineAlpha</a>(SDL_Surface * dst, Sint16 x, Sint16 y1, Sint16 y2, Uint32 color)
<a name="l00922"></a>00922 {
<a name="l00923"></a>00923         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ace9f2505c12c5dacc778509991cd3716" title="Draw filled rectangle of RGBA color with alpha blending.">filledRectAlpha</a>(dst, x, y1, x, y2, color));
<a name="l00924"></a>00924 }
<a name="l00925"></a>00925 
<a name="l00937"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#af9269ad9bbfa20980d5947c85dda63d5">00937</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#af9269ad9bbfa20980d5947c85dda63d5" title="Pixel draw with blending enabled and using alpha weight on color.">pixelColorWeight</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Uint32 color, Uint32 weight)
<a name="l00938"></a>00938 {
<a name="l00939"></a>00939         Uint32 a;
<a name="l00940"></a>00940 
<a name="l00941"></a>00941         <span class="comment">/*</span>
<a name="l00942"></a>00942 <span class="comment">        * Get alpha </span>
<a name="l00943"></a>00943 <span class="comment">        */</span>
<a name="l00944"></a>00944         a = (color &amp; (Uint32) 0x000000ff);
<a name="l00945"></a>00945 
<a name="l00946"></a>00946         <span class="comment">/*</span>
<a name="l00947"></a>00947 <span class="comment">        * Modify Alpha by weight </span>
<a name="l00948"></a>00948 <span class="comment">        */</span>
<a name="l00949"></a>00949         a = ((a * weight) &gt;&gt; 8);
<a name="l00950"></a>00950 
<a name="l00951"></a>00951         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ae6f8690e5c5a85d3263c8e16727b34ef" title="Pixel draw with blending enabled if a&lt;255.">pixelColor</a>(dst, x, y, (color &amp; (Uint32) 0xffffff00) | (Uint32) a));
<a name="l00952"></a>00952 }
<a name="l00953"></a>00953 
<a name="l00965"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#a93c580afe80682f06ef4f1655180aff1">00965</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a93c580afe80682f06ef4f1655180aff1" title="Pixel draw with blending enabled and using alpha weight on color - no locking.">pixelColorWeightNolock</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Uint32 color, Uint32 weight)
<a name="l00966"></a>00966 {
<a name="l00967"></a>00967         Uint32 a;
<a name="l00968"></a>00968 
<a name="l00969"></a>00969         <span class="comment">/*</span>
<a name="l00970"></a>00970 <span class="comment">        * Get alpha </span>
<a name="l00971"></a>00971 <span class="comment">        */</span>
<a name="l00972"></a>00972         a = (color &amp; (Uint32) 0x000000ff);
<a name="l00973"></a>00973 
<a name="l00974"></a>00974         <span class="comment">/*</span>
<a name="l00975"></a>00975 <span class="comment">        * Modify Alpha by weight </span>
<a name="l00976"></a>00976 <span class="comment">        */</span>
<a name="l00977"></a>00977         a = ((a * weight) &gt;&gt; 8);
<a name="l00978"></a>00978 
<a name="l00979"></a>00979         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(dst, x, y, (color &amp; (Uint32) 0xffffff00) | (Uint32) a));
<a name="l00980"></a>00980 }
<a name="l00981"></a>00981 
<a name="l00995"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a0046efc721e77b745fd5b621fbd48513">00995</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a7b6f83bdef72f6b356664a93841381c0" title="Pixel draw with blending enabled if a&lt;255.">pixelRGBA</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l00996"></a>00996 {
<a name="l00997"></a>00997         Uint32 color;
<a name="l00998"></a>00998 
<a name="l00999"></a>00999         <span class="comment">/*</span>
<a name="l01000"></a>01000 <span class="comment">        * Check Alpha </span>
<a name="l01001"></a>01001 <span class="comment">        */</span>
<a name="l01002"></a>01002         <span class="keywordflow">if</span> (a == 255) {
<a name="l01003"></a>01003                 <span class="comment">/*</span>
<a name="l01004"></a>01004 <span class="comment">                * No alpha blending required </span>
<a name="l01005"></a>01005 <span class="comment">                */</span>
<a name="l01006"></a>01006                 <span class="comment">/*</span>
<a name="l01007"></a>01007 <span class="comment">                * Setup color </span>
<a name="l01008"></a>01008 <span class="comment">                */</span>
<a name="l01009"></a>01009                 color = SDL_MapRGBA(dst-&gt;format, r, g, b, a);
<a name="l01010"></a>01010                 <span class="comment">/*</span>
<a name="l01011"></a>01011 <span class="comment">                * Draw </span>
<a name="l01012"></a>01012 <span class="comment">                */</span>
<a name="l01013"></a>01013                 <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#abeed0e873efdf3aec8c6c86188d36f89" title="Internal pixel drawing - fast, no blending, locking, clipping.">fastPixelColor</a>(dst, x, y, color));
<a name="l01014"></a>01014         } <span class="keywordflow">else</span> {
<a name="l01015"></a>01015                 <span class="comment">/*</span>
<a name="l01016"></a>01016 <span class="comment">                * Alpha blending required </span>
<a name="l01017"></a>01017 <span class="comment">                */</span>
<a name="l01018"></a>01018                 <span class="comment">/*</span>
<a name="l01019"></a>01019 <span class="comment">                * Draw </span>
<a name="l01020"></a>01020 <span class="comment">                */</span>
<a name="l01021"></a>01021                 <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ae6f8690e5c5a85d3263c8e16727b34ef" title="Pixel draw with blending enabled if a&lt;255.">pixelColor</a>(dst, x, y, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a));
<a name="l01022"></a>01022         }
<a name="l01023"></a>01023 }
<a name="l01024"></a>01024 
<a name="l01025"></a>01025 
<a name="l01041"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#af20de4fe06f4d997eb2ab01a2252f071">01041</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#af20de4fe06f4d997eb2ab01a2252f071" title="Draw horizontal line without blending;.">hlineColorStore</a>(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16 y, Uint32 color)
<a name="l01042"></a>01042 {
<a name="l01043"></a>01043         Sint16 left, right, top, bottom;
<a name="l01044"></a>01044         Uint8 *pixel, *pixellast;
<a name="l01045"></a>01045         <span class="keywordtype">int</span> dx;
<a name="l01046"></a>01046         <span class="keywordtype">int</span> pixx, pixy;
<a name="l01047"></a>01047         Sint16 w;
<a name="l01048"></a>01048         Sint16 xtmp;
<a name="l01049"></a>01049         <span class="keywordtype">int</span> result = -1;
<a name="l01050"></a>01050 
<a name="l01051"></a>01051         <span class="comment">/*</span>
<a name="l01052"></a>01052 <span class="comment">        * Check visibility of clipping rectangle</span>
<a name="l01053"></a>01053 <span class="comment">        */</span>
<a name="l01054"></a>01054         <span class="keywordflow">if</span> ((dst-&gt;clip_rect.w==0) || (dst-&gt;clip_rect.h==0)) {
<a name="l01055"></a>01055                 <span class="keywordflow">return</span>(0);
<a name="l01056"></a>01056         }
<a name="l01057"></a>01057 
<a name="l01058"></a>01058         <span class="comment">/*</span>
<a name="l01059"></a>01059 <span class="comment">        * Swap x1, x2 if required to ensure x1&lt;=x2</span>
<a name="l01060"></a>01060 <span class="comment">        */</span>
<a name="l01061"></a>01061         <span class="keywordflow">if</span> (x1 &gt; x2) {
<a name="l01062"></a>01062                 xtmp = x1;
<a name="l01063"></a>01063                 x1 = x2;
<a name="l01064"></a>01064                 x2 = xtmp;
<a name="l01065"></a>01065         }
<a name="l01066"></a>01066 
<a name="l01067"></a>01067         <span class="comment">/*</span>
<a name="l01068"></a>01068 <span class="comment">        * Get clipping boundary and</span>
<a name="l01069"></a>01069 <span class="comment">        * check visibility of hline </span>
<a name="l01070"></a>01070 <span class="comment">        */</span>
<a name="l01071"></a>01071         left = dst-&gt;clip_rect.x;
<a name="l01072"></a>01072         <span class="keywordflow">if</span> (x2&lt;left) {
<a name="l01073"></a>01073                 <span class="keywordflow">return</span>(0);
<a name="l01074"></a>01074         }
<a name="l01075"></a>01075         right = dst-&gt;clip_rect.x + dst-&gt;clip_rect.w - 1;
<a name="l01076"></a>01076         <span class="keywordflow">if</span> (x1&gt;right) {
<a name="l01077"></a>01077                 <span class="keywordflow">return</span>(0);
<a name="l01078"></a>01078         }
<a name="l01079"></a>01079         top = dst-&gt;clip_rect.y;
<a name="l01080"></a>01080         bottom = dst-&gt;clip_rect.y + dst-&gt;clip_rect.h - 1;
<a name="l01081"></a>01081         <span class="keywordflow">if</span> ((y&lt;top) || (y&gt;bottom)) {
<a name="l01082"></a>01082                 <span class="keywordflow">return</span> (0);
<a name="l01083"></a>01083         }
<a name="l01084"></a>01084 
<a name="l01085"></a>01085         <span class="comment">/*</span>
<a name="l01086"></a>01086 <span class="comment">        * Clip x </span>
<a name="l01087"></a>01087 <span class="comment">        */</span>
<a name="l01088"></a>01088         <span class="keywordflow">if</span> (x1 &lt; left) {
<a name="l01089"></a>01089                 x1 = left;
<a name="l01090"></a>01090         }
<a name="l01091"></a>01091         <span class="keywordflow">if</span> (x2 &gt; right) {
<a name="l01092"></a>01092                 x2 = right;
<a name="l01093"></a>01093         }
<a name="l01094"></a>01094 
<a name="l01095"></a>01095         <span class="comment">/*</span>
<a name="l01096"></a>01096 <span class="comment">        * Calculate width </span>
<a name="l01097"></a>01097 <span class="comment">        */</span>
<a name="l01098"></a>01098         w = x2 - x1;
<a name="l01099"></a>01099 
<a name="l01100"></a>01100         <span class="comment">/*</span>
<a name="l01101"></a>01101 <span class="comment">        * Lock the surface </span>
<a name="l01102"></a>01102 <span class="comment">        */</span>
<a name="l01103"></a>01103         <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l01104"></a>01104                 <span class="keywordflow">if</span> (SDL_LockSurface(dst) &lt; 0) {
<a name="l01105"></a>01105                         <span class="keywordflow">return</span> (-1);
<a name="l01106"></a>01106                 }
<a name="l01107"></a>01107         }
<a name="l01108"></a>01108 
<a name="l01109"></a>01109         <span class="comment">/*</span>
<a name="l01110"></a>01110 <span class="comment">        * More variable setup </span>
<a name="l01111"></a>01111 <span class="comment">        */</span>
<a name="l01112"></a>01112         dx = w;
<a name="l01113"></a>01113         pixx = dst-&gt;format-&gt;BytesPerPixel;
<a name="l01114"></a>01114         pixy = dst-&gt;pitch;
<a name="l01115"></a>01115         pixel = ((Uint8 *) dst-&gt;pixels) + pixx * (int) x1 + pixy * (<span class="keywordtype">int</span>) y;
<a name="l01116"></a>01116 
<a name="l01117"></a>01117         <span class="comment">/*</span>
<a name="l01118"></a>01118 <span class="comment">        * Draw </span>
<a name="l01119"></a>01119 <span class="comment">        */</span>
<a name="l01120"></a>01120         <span class="keywordflow">switch</span> (dst-&gt;format-&gt;BytesPerPixel) {
<a name="l01121"></a>01121         <span class="keywordflow">case</span> 1:
<a name="l01122"></a>01122                 memset(pixel, color, dx+1);
<a name="l01123"></a>01123                 <span class="keywordflow">break</span>;
<a name="l01124"></a>01124         <span class="keywordflow">case</span> 2:
<a name="l01125"></a>01125                 pixellast = pixel + dx + dx;
<a name="l01126"></a>01126                 <span class="keywordflow">for</span> (; pixel &lt;= pixellast; pixel += pixx) {
<a name="l01127"></a>01127                         *(Uint16 *) pixel = color;
<a name="l01128"></a>01128                 }
<a name="l01129"></a>01129                 <span class="keywordflow">break</span>;
<a name="l01130"></a>01130         <span class="keywordflow">case</span> 3:
<a name="l01131"></a>01131                 pixellast = pixel + dx + dx + dx;
<a name="l01132"></a>01132                 <span class="keywordflow">for</span> (; pixel &lt;= pixellast; pixel += pixx) {
<a name="l01133"></a>01133                         <span class="keywordflow">if</span> (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
<a name="l01134"></a>01134                                 pixel[0] = (color &gt;&gt; 16) &amp; 0xff;
<a name="l01135"></a>01135                                 pixel[1] = (color &gt;&gt; 8) &amp; 0xff;
<a name="l01136"></a>01136                                 pixel[2] = color &amp; 0xff;
<a name="l01137"></a>01137                         } <span class="keywordflow">else</span> {
<a name="l01138"></a>01138                                 pixel[0] = color &amp; 0xff;
<a name="l01139"></a>01139                                 pixel[1] = (color &gt;&gt; 8) &amp; 0xff;
<a name="l01140"></a>01140                                 pixel[2] = (color &gt;&gt; 16) &amp; 0xff;
<a name="l01141"></a>01141                         }
<a name="l01142"></a>01142                 }
<a name="l01143"></a>01143                 <span class="keywordflow">break</span>;
<a name="l01144"></a>01144         <span class="keywordflow">default</span>:                <span class="comment">/* case 4 */</span>
<a name="l01145"></a>01145                 dx = dx + dx;
<a name="l01146"></a>01146                 pixellast = pixel + dx + dx;
<a name="l01147"></a>01147                 <span class="keywordflow">for</span> (; pixel &lt;= pixellast; pixel += pixx) {
<a name="l01148"></a>01148                         *(Uint32 *) pixel = color;
<a name="l01149"></a>01149                 }
<a name="l01150"></a>01150                 <span class="keywordflow">break</span>;
<a name="l01151"></a>01151         }
<a name="l01152"></a>01152 
<a name="l01153"></a>01153         <span class="comment">/* </span>
<a name="l01154"></a>01154 <span class="comment">        * Unlock surface </span>
<a name="l01155"></a>01155 <span class="comment">        */</span>
<a name="l01156"></a>01156         <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l01157"></a>01157                 SDL_UnlockSurface(dst);
<a name="l01158"></a>01158         }
<a name="l01159"></a>01159 
<a name="l01160"></a>01160         <span class="comment">/*</span>
<a name="l01161"></a>01161 <span class="comment">        * Set result code </span>
<a name="l01162"></a>01162 <span class="comment">        */</span>
<a name="l01163"></a>01163         result = 0;
<a name="l01164"></a>01164 
<a name="l01165"></a>01165         <span class="keywordflow">return</span> (result);
<a name="l01166"></a>01166 }
<a name="l01167"></a>01167 
<a name="l01185"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#a1b22ffb35c7690b4b0d8ba901640edae">01185</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a1b22ffb35c7690b4b0d8ba901640edae" title="Draw horizontal line without blending.">hlineRGBAStore</a>(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l01186"></a>01186 {
<a name="l01187"></a>01187         <span class="comment">/*</span>
<a name="l01188"></a>01188 <span class="comment">        * Draw </span>
<a name="l01189"></a>01189 <span class="comment">        */</span>
<a name="l01190"></a>01190         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#af20de4fe06f4d997eb2ab01a2252f071" title="Draw horizontal line without blending;.">hlineColorStore</a>(dst, x1, x2, y, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a));
<a name="l01191"></a>01191 }
<a name="l01192"></a>01192 
<a name="l01204"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a31ac87bf32186325deedf5188b987ef6">01204</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16 y, Uint32 color)
<a name="l01205"></a>01205 {
<a name="l01206"></a>01206         Sint16 left, right, top, bottom;
<a name="l01207"></a>01207         Uint8 *pixel, *pixellast;
<a name="l01208"></a>01208         <span class="keywordtype">int</span> dx;
<a name="l01209"></a>01209         <span class="keywordtype">int</span> pixx, pixy;
<a name="l01210"></a>01210         Sint16 xtmp;
<a name="l01211"></a>01211         <span class="keywordtype">int</span> result = -1;
<a name="l01212"></a>01212         Uint8 *colorptr;
<a name="l01213"></a>01213         Uint8 color3[3];
<a name="l01214"></a>01214 
<a name="l01215"></a>01215         <span class="comment">/*</span>
<a name="l01216"></a>01216 <span class="comment">        * Check visibility of clipping rectangle</span>
<a name="l01217"></a>01217 <span class="comment">        */</span>
<a name="l01218"></a>01218         <span class="keywordflow">if</span> ((dst-&gt;clip_rect.w==0) || (dst-&gt;clip_rect.h==0)) {
<a name="l01219"></a>01219                 <span class="keywordflow">return</span>(0);
<a name="l01220"></a>01220         }
<a name="l01221"></a>01221 
<a name="l01222"></a>01222         <span class="comment">/*</span>
<a name="l01223"></a>01223 <span class="comment">        * Swap x1, x2 if required to ensure x1&lt;=x2</span>
<a name="l01224"></a>01224 <span class="comment">        */</span>
<a name="l01225"></a>01225         <span class="keywordflow">if</span> (x1 &gt; x2) {
<a name="l01226"></a>01226                 xtmp = x1;
<a name="l01227"></a>01227                 x1 = x2;
<a name="l01228"></a>01228                 x2 = xtmp;
<a name="l01229"></a>01229         }
<a name="l01230"></a>01230 
<a name="l01231"></a>01231         <span class="comment">/*</span>
<a name="l01232"></a>01232 <span class="comment">        * Get clipping boundary and</span>
<a name="l01233"></a>01233 <span class="comment">        * check visibility of hline </span>
<a name="l01234"></a>01234 <span class="comment">        */</span>
<a name="l01235"></a>01235         left = dst-&gt;clip_rect.x;
<a name="l01236"></a>01236         <span class="keywordflow">if</span> (x2&lt;left) {
<a name="l01237"></a>01237                 <span class="keywordflow">return</span>(0);
<a name="l01238"></a>01238         }
<a name="l01239"></a>01239         right = dst-&gt;clip_rect.x + dst-&gt;clip_rect.w - 1;
<a name="l01240"></a>01240         <span class="keywordflow">if</span> (x1&gt;right) {
<a name="l01241"></a>01241                 <span class="keywordflow">return</span>(0);
<a name="l01242"></a>01242         }
<a name="l01243"></a>01243         top = dst-&gt;clip_rect.y;
<a name="l01244"></a>01244         bottom = dst-&gt;clip_rect.y + dst-&gt;clip_rect.h - 1;
<a name="l01245"></a>01245         <span class="keywordflow">if</span> ((y&lt;top) || (y&gt;bottom)) {
<a name="l01246"></a>01246                 <span class="keywordflow">return</span> (0);
<a name="l01247"></a>01247         }
<a name="l01248"></a>01248 
<a name="l01249"></a>01249         <span class="comment">/*</span>
<a name="l01250"></a>01250 <span class="comment">        * Clip x </span>
<a name="l01251"></a>01251 <span class="comment">        */</span>
<a name="l01252"></a>01252         <span class="keywordflow">if</span> (x1 &lt; left) {
<a name="l01253"></a>01253                 x1 = left;
<a name="l01254"></a>01254         }
<a name="l01255"></a>01255         <span class="keywordflow">if</span> (x2 &gt; right) {
<a name="l01256"></a>01256                 x2 = right;
<a name="l01257"></a>01257         }
<a name="l01258"></a>01258 
<a name="l01259"></a>01259         <span class="comment">/*</span>
<a name="l01260"></a>01260 <span class="comment">        * Calculate width difference</span>
<a name="l01261"></a>01261 <span class="comment">        */</span>
<a name="l01262"></a>01262         dx = x2 - x1;
<a name="l01263"></a>01263 
<a name="l01264"></a>01264         <span class="comment">/*</span>
<a name="l01265"></a>01265 <span class="comment">        * Alpha check </span>
<a name="l01266"></a>01266 <span class="comment">        */</span>
<a name="l01267"></a>01267         <span class="keywordflow">if</span> ((color &amp; 255) == 255) {
<a name="l01268"></a>01268 
<a name="l01269"></a>01269                 <span class="comment">/*</span>
<a name="l01270"></a>01270 <span class="comment">                * No alpha-blending required </span>
<a name="l01271"></a>01271 <span class="comment">                */</span>
<a name="l01272"></a>01272 
<a name="l01273"></a>01273                 <span class="comment">/*</span>
<a name="l01274"></a>01274 <span class="comment">                * Setup color </span>
<a name="l01275"></a>01275 <span class="comment">                */</span>
<a name="l01276"></a>01276                 colorptr = (Uint8 *) &amp; color;
<a name="l01277"></a>01277                 <span class="keywordflow">if</span> (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
<a name="l01278"></a>01278                         color = SDL_MapRGBA(dst-&gt;format, colorptr[0], colorptr[1], colorptr[2], colorptr[3]);
<a name="l01279"></a>01279                 } <span class="keywordflow">else</span> {
<a name="l01280"></a>01280                         color = SDL_MapRGBA(dst-&gt;format, colorptr[3], colorptr[2], colorptr[1], colorptr[0]);
<a name="l01281"></a>01281                 }
<a name="l01282"></a>01282 
<a name="l01283"></a>01283                 <span class="comment">/*</span>
<a name="l01284"></a>01284 <span class="comment">                * Lock the surface </span>
<a name="l01285"></a>01285 <span class="comment">                */</span>
<a name="l01286"></a>01286                 <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l01287"></a>01287                         <span class="keywordflow">if</span> (SDL_LockSurface(dst) &lt; 0) {
<a name="l01288"></a>01288                                 <span class="keywordflow">return</span> (-1);
<a name="l01289"></a>01289                         }
<a name="l01290"></a>01290                 }
<a name="l01291"></a>01291 
<a name="l01292"></a>01292                 <span class="comment">/*</span>
<a name="l01293"></a>01293 <span class="comment">                * More variable setup </span>
<a name="l01294"></a>01294 <span class="comment">                */</span>
<a name="l01295"></a>01295                 pixx = dst-&gt;format-&gt;BytesPerPixel;
<a name="l01296"></a>01296                 pixy = dst-&gt;pitch;
<a name="l01297"></a>01297                 pixel = ((Uint8 *) dst-&gt;pixels) + pixx * (int) x1 + pixy * (<span class="keywordtype">int</span>) y;
<a name="l01298"></a>01298 
<a name="l01299"></a>01299                 <span class="comment">/*</span>
<a name="l01300"></a>01300 <span class="comment">                * Draw </span>
<a name="l01301"></a>01301 <span class="comment">                */</span>
<a name="l01302"></a>01302                 <span class="keywordflow">switch</span> (dst-&gt;format-&gt;BytesPerPixel) {
<a name="l01303"></a>01303                 <span class="keywordflow">case</span> 1:
<a name="l01304"></a>01304                         memset(pixel, color, dx + 1);
<a name="l01305"></a>01305                         <span class="keywordflow">break</span>;
<a name="l01306"></a>01306                 <span class="keywordflow">case</span> 2:
<a name="l01307"></a>01307                         pixellast = pixel + dx + dx;
<a name="l01308"></a>01308                         <span class="keywordflow">for</span> (; pixel &lt;= pixellast; pixel += pixx) {
<a name="l01309"></a>01309                                 *(Uint16 *) pixel = color;
<a name="l01310"></a>01310                         }
<a name="l01311"></a>01311                         <span class="keywordflow">break</span>;
<a name="l01312"></a>01312                 <span class="keywordflow">case</span> 3:
<a name="l01313"></a>01313                         pixellast = pixel + dx + dx + dx;
<a name="l01314"></a>01314                         <span class="keywordflow">if</span> (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
<a name="l01315"></a>01315                                 color3[0] = (color &gt;&gt; 16) &amp; 0xff;
<a name="l01316"></a>01316                                 color3[1] = (color &gt;&gt; 8) &amp; 0xff;
<a name="l01317"></a>01317                                 color3[2] = color &amp; 0xff;
<a name="l01318"></a>01318                         } <span class="keywordflow">else</span> {
<a name="l01319"></a>01319                                 color3[0] = color &amp; 0xff;
<a name="l01320"></a>01320                                 color3[1] = (color &gt;&gt; 8) &amp; 0xff;
<a name="l01321"></a>01321                                 color3[2] = (color &gt;&gt; 16) &amp; 0xff;
<a name="l01322"></a>01322                         }
<a name="l01323"></a>01323                         <span class="keywordflow">for</span> (; pixel &lt;= pixellast; pixel += pixx) {
<a name="l01324"></a>01324                                 memcpy(pixel, color3, 3);
<a name="l01325"></a>01325                         }
<a name="l01326"></a>01326                         <span class="keywordflow">break</span>;
<a name="l01327"></a>01327                 <span class="keywordflow">default</span>:                <span class="comment">/* case 4 */</span>
<a name="l01328"></a>01328                         dx = dx + dx;
<a name="l01329"></a>01329                         pixellast = pixel + dx + dx;
<a name="l01330"></a>01330                         <span class="keywordflow">for</span> (; pixel &lt;= pixellast; pixel += pixx) {
<a name="l01331"></a>01331                                 *(Uint32 *) pixel = color;
<a name="l01332"></a>01332                         }
<a name="l01333"></a>01333                         <span class="keywordflow">break</span>;
<a name="l01334"></a>01334                 }
<a name="l01335"></a>01335 
<a name="l01336"></a>01336                 <span class="comment">/* </span>
<a name="l01337"></a>01337 <span class="comment">                * Unlock surface </span>
<a name="l01338"></a>01338 <span class="comment">                */</span>
<a name="l01339"></a>01339                 <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l01340"></a>01340                         SDL_UnlockSurface(dst);
<a name="l01341"></a>01341                 }
<a name="l01342"></a>01342 
<a name="l01343"></a>01343                 <span class="comment">/*</span>
<a name="l01344"></a>01344 <span class="comment">                * Set result code </span>
<a name="l01345"></a>01345 <span class="comment">                */</span>
<a name="l01346"></a>01346                 result = 0;
<a name="l01347"></a>01347 
<a name="l01348"></a>01348         } <span class="keywordflow">else</span> {
<a name="l01349"></a>01349 
<a name="l01350"></a>01350                 <span class="comment">/*</span>
<a name="l01351"></a>01351 <span class="comment">                * Alpha blending blit </span>
<a name="l01352"></a>01352 <span class="comment">                */</span>
<a name="l01353"></a>01353                 result = <a class="code" href="_s_d_l__gfx_primitives_8c.html#a9eb9c20c69b527cda814a19212270efa" title="Internal function to draw horizontal line of RGBA color with alpha blending.">_HLineAlpha</a>(dst, x1, x1 + dx, y, color);
<a name="l01354"></a>01354         }
<a name="l01355"></a>01355 
<a name="l01356"></a>01356         <span class="keywordflow">return</span> (result);
<a name="l01357"></a>01357 }
<a name="l01358"></a>01358 
<a name="l01373"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#ae48e69e0f5d13ea79ffac262b146ae9e">01373</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a6608a0d1d4c7e16fa1afcbd3eb5c3850" title="Draw horizontal line with blending.">hlineRGBA</a>(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l01374"></a>01374 {
<a name="l01375"></a>01375         <span class="comment">/*</span>
<a name="l01376"></a>01376 <span class="comment">        * Draw </span>
<a name="l01377"></a>01377 <span class="comment">        */</span>
<a name="l01378"></a>01378         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, x1, x2, y, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a));
<a name="l01379"></a>01379 }
<a name="l01380"></a>01380 
<a name="l01392"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#ab68d565f00527a67c9d88121c753302c">01392</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a9b45060155a19fee24f998d7790f1d67" title="Draw vertical line with blending.">vlineColor</a>(SDL_Surface * dst, Sint16 x, Sint16 y1, Sint16 y2, Uint32 color)
<a name="l01393"></a>01393 {
<a name="l01394"></a>01394         Sint16 left, right, top, bottom;
<a name="l01395"></a>01395         Uint8 *pixel, *pixellast;
<a name="l01396"></a>01396         <span class="keywordtype">int</span> dy;
<a name="l01397"></a>01397         <span class="keywordtype">int</span> pixx, pixy;
<a name="l01398"></a>01398         Sint16 h;
<a name="l01399"></a>01399         Sint16 ytmp;
<a name="l01400"></a>01400         <span class="keywordtype">int</span> result = -1;
<a name="l01401"></a>01401         Uint8 *colorptr;
<a name="l01402"></a>01402 
<a name="l01403"></a>01403         <span class="comment">/*</span>
<a name="l01404"></a>01404 <span class="comment">        * Check visibility of clipping rectangle</span>
<a name="l01405"></a>01405 <span class="comment">        */</span>
<a name="l01406"></a>01406         <span class="keywordflow">if</span> ((dst-&gt;clip_rect.w==0) || (dst-&gt;clip_rect.h==0)) {
<a name="l01407"></a>01407                 <span class="keywordflow">return</span>(0);
<a name="l01408"></a>01408         }
<a name="l01409"></a>01409 
<a name="l01410"></a>01410         <span class="comment">/*</span>
<a name="l01411"></a>01411 <span class="comment">        * Swap y1, y2 if required to ensure y1&lt;=y2</span>
<a name="l01412"></a>01412 <span class="comment">        */</span>
<a name="l01413"></a>01413         <span class="keywordflow">if</span> (y1 &gt; y2) {
<a name="l01414"></a>01414                 ytmp = y1;
<a name="l01415"></a>01415                 y1 = y2;
<a name="l01416"></a>01416                 y2 = ytmp;
<a name="l01417"></a>01417         }
<a name="l01418"></a>01418 
<a name="l01419"></a>01419         <span class="comment">/*</span>
<a name="l01420"></a>01420 <span class="comment">        * Get clipping boundary and</span>
<a name="l01421"></a>01421 <span class="comment">        * check visibility of vline </span>
<a name="l01422"></a>01422 <span class="comment">        */</span>
<a name="l01423"></a>01423         left = dst-&gt;clip_rect.x;
<a name="l01424"></a>01424         right = dst-&gt;clip_rect.x + dst-&gt;clip_rect.w - 1;
<a name="l01425"></a>01425         <span class="keywordflow">if</span> ((x&lt;left) || (x&gt;right)) {
<a name="l01426"></a>01426                 <span class="keywordflow">return</span> (0);
<a name="l01427"></a>01427         }    
<a name="l01428"></a>01428         top = dst-&gt;clip_rect.y;
<a name="l01429"></a>01429         <span class="keywordflow">if</span> (y2&lt;top) {
<a name="l01430"></a>01430                 <span class="keywordflow">return</span>(0);
<a name="l01431"></a>01431         }
<a name="l01432"></a>01432         bottom = dst-&gt;clip_rect.y + dst-&gt;clip_rect.h - 1;
<a name="l01433"></a>01433         <span class="keywordflow">if</span> (y1&gt;bottom) {
<a name="l01434"></a>01434                 <span class="keywordflow">return</span>(0);
<a name="l01435"></a>01435         }
<a name="l01436"></a>01436 
<a name="l01437"></a>01437         <span class="comment">/*</span>
<a name="l01438"></a>01438 <span class="comment">        * Clip x </span>
<a name="l01439"></a>01439 <span class="comment">        */</span>
<a name="l01440"></a>01440         <span class="keywordflow">if</span> (y1 &lt; top) {
<a name="l01441"></a>01441                 y1 = top;
<a name="l01442"></a>01442         }
<a name="l01443"></a>01443         <span class="keywordflow">if</span> (y2 &gt; bottom) {
<a name="l01444"></a>01444                 y2 = bottom;
<a name="l01445"></a>01445         }
<a name="l01446"></a>01446 
<a name="l01447"></a>01447         <span class="comment">/*</span>
<a name="l01448"></a>01448 <span class="comment">        * Calculate height</span>
<a name="l01449"></a>01449 <span class="comment">        */</span>
<a name="l01450"></a>01450         h = y2 - y1;
<a name="l01451"></a>01451 
<a name="l01452"></a>01452         <span class="comment">/*</span>
<a name="l01453"></a>01453 <span class="comment">        * Alpha check </span>
<a name="l01454"></a>01454 <span class="comment">        */</span>
<a name="l01455"></a>01455         <span class="keywordflow">if</span> ((color &amp; 255) == 255) {
<a name="l01456"></a>01456 
<a name="l01457"></a>01457                 <span class="comment">/*</span>
<a name="l01458"></a>01458 <span class="comment">                * No alpha-blending required </span>
<a name="l01459"></a>01459 <span class="comment">                */</span>
<a name="l01460"></a>01460 
<a name="l01461"></a>01461                 <span class="comment">/*</span>
<a name="l01462"></a>01462 <span class="comment">                * Setup color </span>
<a name="l01463"></a>01463 <span class="comment">                */</span>
<a name="l01464"></a>01464                 colorptr = (Uint8 *) &amp; color;
<a name="l01465"></a>01465                 <span class="keywordflow">if</span> (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
<a name="l01466"></a>01466                         color = SDL_MapRGBA(dst-&gt;format, colorptr[0], colorptr[1], colorptr[2], colorptr[3]);
<a name="l01467"></a>01467                 } <span class="keywordflow">else</span> {
<a name="l01468"></a>01468                         color = SDL_MapRGBA(dst-&gt;format, colorptr[3], colorptr[2], colorptr[1], colorptr[0]);
<a name="l01469"></a>01469                 }
<a name="l01470"></a>01470 
<a name="l01471"></a>01471                 <span class="comment">/*</span>
<a name="l01472"></a>01472 <span class="comment">                * Lock the surface </span>
<a name="l01473"></a>01473 <span class="comment">                */</span>
<a name="l01474"></a>01474                 <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l01475"></a>01475                         <span class="keywordflow">if</span> (SDL_LockSurface(dst) &lt; 0) {
<a name="l01476"></a>01476                                 <span class="keywordflow">return</span> (-1);
<a name="l01477"></a>01477                         }
<a name="l01478"></a>01478                 }
<a name="l01479"></a>01479 
<a name="l01480"></a>01480                 <span class="comment">/*</span>
<a name="l01481"></a>01481 <span class="comment">                * More variable setup </span>
<a name="l01482"></a>01482 <span class="comment">                */</span>
<a name="l01483"></a>01483                 dy = h;
<a name="l01484"></a>01484                 pixx = dst-&gt;format-&gt;BytesPerPixel;
<a name="l01485"></a>01485                 pixy = dst-&gt;pitch;
<a name="l01486"></a>01486                 pixel = ((Uint8 *) dst-&gt;pixels) + pixx * (int) x + pixy * (<span class="keywordtype">int</span>) y1;
<a name="l01487"></a>01487                 pixellast = pixel + pixy * dy;
<a name="l01488"></a>01488 
<a name="l01489"></a>01489                 <span class="comment">/*</span>
<a name="l01490"></a>01490 <span class="comment">                * Draw </span>
<a name="l01491"></a>01491 <span class="comment">                */</span>
<a name="l01492"></a>01492                 <span class="keywordflow">switch</span> (dst-&gt;format-&gt;BytesPerPixel) {
<a name="l01493"></a>01493                 <span class="keywordflow">case</span> 1:
<a name="l01494"></a>01494                         <span class="keywordflow">for</span> (; pixel &lt;= pixellast; pixel += pixy) {
<a name="l01495"></a>01495                                 *(Uint8 *) pixel = color;
<a name="l01496"></a>01496                         }
<a name="l01497"></a>01497                         <span class="keywordflow">break</span>;
<a name="l01498"></a>01498                 <span class="keywordflow">case</span> 2:
<a name="l01499"></a>01499                         <span class="keywordflow">for</span> (; pixel &lt;= pixellast; pixel += pixy) {
<a name="l01500"></a>01500                                 *(Uint16 *) pixel = color;
<a name="l01501"></a>01501                         }
<a name="l01502"></a>01502                         <span class="keywordflow">break</span>;
<a name="l01503"></a>01503                 <span class="keywordflow">case</span> 3:
<a name="l01504"></a>01504                         <span class="keywordflow">for</span> (; pixel &lt;= pixellast; pixel += pixy) {
<a name="l01505"></a>01505                                 <span class="keywordflow">if</span> (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
<a name="l01506"></a>01506                                         pixel[0] = (color &gt;&gt; 16) &amp; 0xff;
<a name="l01507"></a>01507                                         pixel[1] = (color &gt;&gt; 8) &amp; 0xff;
<a name="l01508"></a>01508                                         pixel[2] = color &amp; 0xff;
<a name="l01509"></a>01509                                 } <span class="keywordflow">else</span> {
<a name="l01510"></a>01510                                         pixel[0] = color &amp; 0xff;
<a name="l01511"></a>01511                                         pixel[1] = (color &gt;&gt; 8) &amp; 0xff;
<a name="l01512"></a>01512                                         pixel[2] = (color &gt;&gt; 16) &amp; 0xff;
<a name="l01513"></a>01513                                 }
<a name="l01514"></a>01514                         }
<a name="l01515"></a>01515                         <span class="keywordflow">break</span>;
<a name="l01516"></a>01516                 <span class="keywordflow">default</span>:                <span class="comment">/* case 4 */</span>
<a name="l01517"></a>01517                         <span class="keywordflow">for</span> (; pixel &lt;= pixellast; pixel += pixy) {
<a name="l01518"></a>01518                                 *(Uint32 *) pixel = color;
<a name="l01519"></a>01519                         }
<a name="l01520"></a>01520                         <span class="keywordflow">break</span>;
<a name="l01521"></a>01521                 }
<a name="l01522"></a>01522 
<a name="l01523"></a>01523                 <span class="comment">/* Unlock surface */</span>
<a name="l01524"></a>01524                 <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l01525"></a>01525                         SDL_UnlockSurface(dst);
<a name="l01526"></a>01526                 }
<a name="l01527"></a>01527 
<a name="l01528"></a>01528                 <span class="comment">/*</span>
<a name="l01529"></a>01529 <span class="comment">                * Set result code </span>
<a name="l01530"></a>01530 <span class="comment">                */</span>
<a name="l01531"></a>01531                 result = 0;
<a name="l01532"></a>01532 
<a name="l01533"></a>01533         } <span class="keywordflow">else</span> {
<a name="l01534"></a>01534 
<a name="l01535"></a>01535                 <span class="comment">/*</span>
<a name="l01536"></a>01536 <span class="comment">                * Alpha blending blit </span>
<a name="l01537"></a>01537 <span class="comment">                */</span>
<a name="l01538"></a>01538 
<a name="l01539"></a>01539                 result = <a class="code" href="_s_d_l__gfx_primitives_8c.html#a61dd5e7523ce84fb103da3338acd3a37" title="Internal function to draw vertical line of RGBA color with alpha blending.">_VLineAlpha</a>(dst, x, y1, y1 + h, color);
<a name="l01540"></a>01540 
<a name="l01541"></a>01541         }
<a name="l01542"></a>01542 
<a name="l01543"></a>01543         <span class="keywordflow">return</span> (result);
<a name="l01544"></a>01544 }
<a name="l01545"></a>01545 
<a name="l01560"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a68ed9a65e3e0de26136566b0cf0c859e">01560</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a8b79ac1e779755aee92b04f3a6cfc5d7" title="Draw vertical line with blending.">vlineRGBA</a>(SDL_Surface * dst, Sint16 x, Sint16 y1, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l01561"></a>01561 {
<a name="l01562"></a>01562         <span class="comment">/*</span>
<a name="l01563"></a>01563 <span class="comment">        * Draw </span>
<a name="l01564"></a>01564 <span class="comment">        */</span>
<a name="l01565"></a>01565         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a9b45060155a19fee24f998d7790f1d67" title="Draw vertical line with blending.">vlineColor</a>(dst, x, y1, y2, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a));
<a name="l01566"></a>01566 }
<a name="l01567"></a>01567 
<a name="l01580"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a36453f52608a10f3d6b8edccae260b95">01580</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a6ab25c393f6e5f8d68ea3365f6ea98d2" title="Draw rectangle with blending.">rectangleColor</a>(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color)
<a name="l01581"></a>01581 {
<a name="l01582"></a>01582         <span class="keywordtype">int</span> result;
<a name="l01583"></a>01583         Sint16 tmp;
<a name="l01584"></a>01584 
<a name="l01585"></a>01585         <span class="comment">/* Check destination surface */</span>
<a name="l01586"></a>01586         <span class="keywordflow">if</span> (dst == NULL)
<a name="l01587"></a>01587         {
<a name="l01588"></a>01588                 <span class="keywordflow">return</span> -1;
<a name="l01589"></a>01589         }
<a name="l01590"></a>01590 
<a name="l01591"></a>01591         <span class="comment">/*</span>
<a name="l01592"></a>01592 <span class="comment">        * Check visibility of clipping rectangle</span>
<a name="l01593"></a>01593 <span class="comment">        */</span>
<a name="l01594"></a>01594         <span class="keywordflow">if</span> ((dst-&gt;clip_rect.w==0) || (dst-&gt;clip_rect.h==0)) {
<a name="l01595"></a>01595                 <span class="keywordflow">return</span> 0;
<a name="l01596"></a>01596         }
<a name="l01597"></a>01597 
<a name="l01598"></a>01598         <span class="comment">/*</span>
<a name="l01599"></a>01599 <span class="comment">        * Test for special cases of straight lines or single point </span>
<a name="l01600"></a>01600 <span class="comment">        */</span>
<a name="l01601"></a>01601         <span class="keywordflow">if</span> (x1 == x2) {
<a name="l01602"></a>01602                 <span class="keywordflow">if</span> (y1 == y2) {
<a name="l01603"></a>01603                         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ae6f8690e5c5a85d3263c8e16727b34ef" title="Pixel draw with blending enabled if a&lt;255.">pixelColor</a>(dst, x1, y1, color));
<a name="l01604"></a>01604                 } <span class="keywordflow">else</span> {
<a name="l01605"></a>01605                         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a9b45060155a19fee24f998d7790f1d67" title="Draw vertical line with blending.">vlineColor</a>(dst, x1, y1, y2, color));
<a name="l01606"></a>01606                 }
<a name="l01607"></a>01607         } <span class="keywordflow">else</span> {
<a name="l01608"></a>01608                 <span class="keywordflow">if</span> (y1 == y2) {
<a name="l01609"></a>01609                         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, x1, x2, y1, color));
<a name="l01610"></a>01610                 }
<a name="l01611"></a>01611         }
<a name="l01612"></a>01612 
<a name="l01613"></a>01613         <span class="comment">/*</span>
<a name="l01614"></a>01614 <span class="comment">        * Swap x1, x2 if required </span>
<a name="l01615"></a>01615 <span class="comment">        */</span>
<a name="l01616"></a>01616         <span class="keywordflow">if</span> (x1 &gt; x2) {
<a name="l01617"></a>01617                 tmp = x1;
<a name="l01618"></a>01618                 x1 = x2;
<a name="l01619"></a>01619                 x2 = tmp;
<a name="l01620"></a>01620         }
<a name="l01621"></a>01621 
<a name="l01622"></a>01622         <span class="comment">/*</span>
<a name="l01623"></a>01623 <span class="comment">        * Swap y1, y2 if required </span>
<a name="l01624"></a>01624 <span class="comment">        */</span>
<a name="l01625"></a>01625         <span class="keywordflow">if</span> (y1 &gt; y2) {
<a name="l01626"></a>01626                 tmp = y1;
<a name="l01627"></a>01627                 y1 = y2;
<a name="l01628"></a>01628                 y2 = tmp;
<a name="l01629"></a>01629         }
<a name="l01630"></a>01630 
<a name="l01631"></a>01631         <span class="comment">/*</span>
<a name="l01632"></a>01632 <span class="comment">        * Draw rectangle </span>
<a name="l01633"></a>01633 <span class="comment">        */</span>
<a name="l01634"></a>01634         result = 0;
<a name="l01635"></a>01635         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, x1, x2, y1, color);
<a name="l01636"></a>01636         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, x1, x2, y2, color);
<a name="l01637"></a>01637         y1 += 1;
<a name="l01638"></a>01638         y2 -= 1;
<a name="l01639"></a>01639         <span class="keywordflow">if</span> (y1 &lt;= y2) {
<a name="l01640"></a>01640                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a9b45060155a19fee24f998d7790f1d67" title="Draw vertical line with blending.">vlineColor</a>(dst, x1, y1, y2, color);
<a name="l01641"></a>01641                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a9b45060155a19fee24f998d7790f1d67" title="Draw vertical line with blending.">vlineColor</a>(dst, x2, y1, y2, color);
<a name="l01642"></a>01642         }
<a name="l01643"></a>01643 
<a name="l01644"></a>01644         <span class="keywordflow">return</span> (result);
<a name="l01645"></a>01645 
<a name="l01646"></a>01646 }
<a name="l01647"></a>01647 
<a name="l01663"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a6c41cbfd0618262de4d4d127ed1e67fe">01663</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a40991c6eeb936d35d0a8e8aa95268f72" title="Draw rectangle with blending.">rectangleRGBA</a>(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l01664"></a>01664 {
<a name="l01665"></a>01665         <span class="comment">/*</span>
<a name="l01666"></a>01666 <span class="comment">        * Draw </span>
<a name="l01667"></a>01667 <span class="comment">        */</span>
<a name="l01668"></a>01668         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a6ab25c393f6e5f8d68ea3365f6ea98d2" title="Draw rectangle with blending.">rectangleColor</a>
<a name="l01669"></a>01669                 (dst, x1, y1, x2, y2, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a));
<a name="l01670"></a>01670 }
<a name="l01671"></a>01671 
<a name="l01685"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a4109d2d1efa021c021fc4a98a0e3691b">01685</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a830dd9dcfa39f4718aa2c269060326d0" title="Draw rounded-corner rectangle with blending.">roundedRectangleColor</a>(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 rad, Uint32 color)
<a name="l01686"></a>01686 {
<a name="l01687"></a>01687         <span class="keywordtype">int</span> result;
<a name="l01688"></a>01688         Sint16 w, h, tmp;
<a name="l01689"></a>01689         Sint16 xx1, xx2, yy1, yy2;
<a name="l01690"></a>01690 
<a name="l01691"></a>01691         <span class="comment">/* </span>
<a name="l01692"></a>01692 <span class="comment">        * Check destination surface </span>
<a name="l01693"></a>01693 <span class="comment">        */</span>
<a name="l01694"></a>01694         <span class="keywordflow">if</span> (dst == NULL)
<a name="l01695"></a>01695         {
<a name="l01696"></a>01696                 <span class="keywordflow">return</span> -1;
<a name="l01697"></a>01697         }
<a name="l01698"></a>01698 
<a name="l01699"></a>01699         <span class="comment">/*</span>
<a name="l01700"></a>01700 <span class="comment">        * Check radius vor valid range</span>
<a name="l01701"></a>01701 <span class="comment">        */</span>
<a name="l01702"></a>01702         <span class="keywordflow">if</span> (rad &lt; 0) {
<a name="l01703"></a>01703                 <span class="keywordflow">return</span> -1;
<a name="l01704"></a>01704         }
<a name="l01705"></a>01705 
<a name="l01706"></a>01706         <span class="comment">/*</span>
<a name="l01707"></a>01707 <span class="comment">        * Special case - no rounding</span>
<a name="l01708"></a>01708 <span class="comment">        */</span>
<a name="l01709"></a>01709         <span class="keywordflow">if</span> (rad == 0) {
<a name="l01710"></a>01710                 <span class="keywordflow">return</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a6ab25c393f6e5f8d68ea3365f6ea98d2" title="Draw rectangle with blending.">rectangleColor</a>(dst, x1, y1, x2, y2, color);
<a name="l01711"></a>01711         }
<a name="l01712"></a>01712 
<a name="l01713"></a>01713         <span class="comment">/*</span>
<a name="l01714"></a>01714 <span class="comment">        * Check visibility of clipping rectangle</span>
<a name="l01715"></a>01715 <span class="comment">        */</span>
<a name="l01716"></a>01716         <span class="keywordflow">if</span> ((dst-&gt;clip_rect.w==0) || (dst-&gt;clip_rect.h==0)) {
<a name="l01717"></a>01717                 <span class="keywordflow">return</span> 0;
<a name="l01718"></a>01718         }
<a name="l01719"></a>01719 
<a name="l01720"></a>01720         <span class="comment">/*</span>
<a name="l01721"></a>01721 <span class="comment">        * Test for special cases of straight lines or single point </span>
<a name="l01722"></a>01722 <span class="comment">        */</span>
<a name="l01723"></a>01723         <span class="keywordflow">if</span> (x1 == x2) {
<a name="l01724"></a>01724                 <span class="keywordflow">if</span> (y1 == y2) {
<a name="l01725"></a>01725                         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ae6f8690e5c5a85d3263c8e16727b34ef" title="Pixel draw with blending enabled if a&lt;255.">pixelColor</a>(dst, x1, y1, color));
<a name="l01726"></a>01726                 } <span class="keywordflow">else</span> {
<a name="l01727"></a>01727                         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a9b45060155a19fee24f998d7790f1d67" title="Draw vertical line with blending.">vlineColor</a>(dst, x1, y1, y2, color));
<a name="l01728"></a>01728                 }
<a name="l01729"></a>01729         } <span class="keywordflow">else</span> {
<a name="l01730"></a>01730                 <span class="keywordflow">if</span> (y1 == y2) {
<a name="l01731"></a>01731                         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, x1, x2, y1, color));
<a name="l01732"></a>01732                 }
<a name="l01733"></a>01733         }
<a name="l01734"></a>01734 
<a name="l01735"></a>01735         <span class="comment">/*</span>
<a name="l01736"></a>01736 <span class="comment">        * Swap x1, x2 if required </span>
<a name="l01737"></a>01737 <span class="comment">        */</span>
<a name="l01738"></a>01738         <span class="keywordflow">if</span> (x1 &gt; x2) {
<a name="l01739"></a>01739                 tmp = x1;
<a name="l01740"></a>01740                 x1 = x2;
<a name="l01741"></a>01741                 x2 = tmp;
<a name="l01742"></a>01742         }
<a name="l01743"></a>01743 
<a name="l01744"></a>01744         <span class="comment">/*</span>
<a name="l01745"></a>01745 <span class="comment">        * Swap y1, y2 if required </span>
<a name="l01746"></a>01746 <span class="comment">        */</span>
<a name="l01747"></a>01747         <span class="keywordflow">if</span> (y1 &gt; y2) {
<a name="l01748"></a>01748                 tmp = y1;
<a name="l01749"></a>01749                 y1 = y2;
<a name="l01750"></a>01750                 y2 = tmp;
<a name="l01751"></a>01751         }
<a name="l01752"></a>01752 
<a name="l01753"></a>01753         <span class="comment">/*</span>
<a name="l01754"></a>01754 <span class="comment">        * Calculate width&amp;height </span>
<a name="l01755"></a>01755 <span class="comment">        */</span>
<a name="l01756"></a>01756         w = x2 - x1;
<a name="l01757"></a>01757         h = y2 - y1;
<a name="l01758"></a>01758 
<a name="l01759"></a>01759         <span class="comment">/*</span>
<a name="l01760"></a>01760 <span class="comment">        * Maybe adjust radius</span>
<a name="l01761"></a>01761 <span class="comment">        */</span>
<a name="l01762"></a>01762         <span class="keywordflow">if</span> ((rad * 2) &gt; w)  
<a name="l01763"></a>01763         {
<a name="l01764"></a>01764                 rad = w / 2;
<a name="l01765"></a>01765         }
<a name="l01766"></a>01766         <span class="keywordflow">if</span> ((rad * 2) &gt; h)
<a name="l01767"></a>01767         {
<a name="l01768"></a>01768                 rad = h / 2;
<a name="l01769"></a>01769         }
<a name="l01770"></a>01770 
<a name="l01771"></a>01771         <span class="comment">/*</span>
<a name="l01772"></a>01772 <span class="comment">        * Draw corners</span>
<a name="l01773"></a>01773 <span class="comment">        */</span>
<a name="l01774"></a>01774         result = 0;
<a name="l01775"></a>01775         xx1 = x1 + rad;
<a name="l01776"></a>01776         xx2 = x2 - rad;
<a name="l01777"></a>01777         yy1 = y1 + rad;
<a name="l01778"></a>01778         yy2 = y2 - rad;
<a name="l01779"></a>01779         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a461b8ac31e00306aee5f8a4c242671d2" title="Arc with blending.">arcColor</a>(dst, xx1, yy1, rad, 180, 270, color);
<a name="l01780"></a>01780         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a461b8ac31e00306aee5f8a4c242671d2" title="Arc with blending.">arcColor</a>(dst, xx2, yy1, rad, 270, 360, color);
<a name="l01781"></a>01781         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a461b8ac31e00306aee5f8a4c242671d2" title="Arc with blending.">arcColor</a>(dst, xx1, yy2, rad,  90, 180, color);
<a name="l01782"></a>01782         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a461b8ac31e00306aee5f8a4c242671d2" title="Arc with blending.">arcColor</a>(dst, xx2, yy2, rad,   0,  90, color);
<a name="l01783"></a>01783 
<a name="l01784"></a>01784         <span class="comment">/*</span>
<a name="l01785"></a>01785 <span class="comment">        * Draw lines</span>
<a name="l01786"></a>01786 <span class="comment">        */</span>
<a name="l01787"></a>01787         <span class="keywordflow">if</span> (xx1 &lt;= xx2) {
<a name="l01788"></a>01788                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, xx1, xx2, y1, color);
<a name="l01789"></a>01789                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, xx1, xx2, y2, color);
<a name="l01790"></a>01790         }
<a name="l01791"></a>01791         <span class="keywordflow">if</span> (yy1 &lt;= yy2) {
<a name="l01792"></a>01792                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a9b45060155a19fee24f998d7790f1d67" title="Draw vertical line with blending.">vlineColor</a>(dst, x1, yy1, yy2, color);
<a name="l01793"></a>01793                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a9b45060155a19fee24f998d7790f1d67" title="Draw vertical line with blending.">vlineColor</a>(dst, x2, yy1, yy2, color);
<a name="l01794"></a>01794         }
<a name="l01795"></a>01795 
<a name="l01796"></a>01796         <span class="keywordflow">return</span> result;
<a name="l01797"></a>01797 }
<a name="l01798"></a>01798 
<a name="l01815"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a475432abc4756e6f30ef097d5cac02c9">01815</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a300272b3b799f09ca6cd5c541b19f07a" title="Draw rounded-corner rectangle with blending.">roundedRectangleRGBA</a>(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l01816"></a>01816 {
<a name="l01817"></a>01817         <span class="comment">/*</span>
<a name="l01818"></a>01818 <span class="comment">        * Draw </span>
<a name="l01819"></a>01819 <span class="comment">        */</span>
<a name="l01820"></a>01820         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a830dd9dcfa39f4718aa2c269060326d0" title="Draw rounded-corner rectangle with blending.">roundedRectangleColor</a>
<a name="l01821"></a>01821                 (dst, x1, y1, x2, y2, rad, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a));
<a name="l01822"></a>01822 }
<a name="l01823"></a>01823 
<a name="l01837"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a9f9be6e605e764fd23dd154fb12b80e9">01837</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a718c4f31d1e145106959c2a77d5fee9d" title="Draw rounded-corner box (filled rectangle) with blending.">roundedBoxColor</a>(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 rad, Uint32 color)
<a name="l01838"></a>01838 {
<a name="l01839"></a>01839         <span class="keywordtype">int</span> result;
<a name="l01840"></a>01840         Sint16 w, h, tmp;
<a name="l01841"></a>01841         Sint16 xx1, xx2, yy1, yy2;
<a name="l01842"></a>01842 
<a name="l01843"></a>01843         <span class="comment">/* </span>
<a name="l01844"></a>01844 <span class="comment">        * Check destination surface </span>
<a name="l01845"></a>01845 <span class="comment">        */</span>
<a name="l01846"></a>01846         <span class="keywordflow">if</span> (dst == NULL)
<a name="l01847"></a>01847         {
<a name="l01848"></a>01848                 <span class="keywordflow">return</span> -1;
<a name="l01849"></a>01849         }
<a name="l01850"></a>01850 
<a name="l01851"></a>01851         <span class="comment">/*</span>
<a name="l01852"></a>01852 <span class="comment">        * Check radius vor valid range</span>
<a name="l01853"></a>01853 <span class="comment">        */</span>
<a name="l01854"></a>01854         <span class="keywordflow">if</span> (rad &lt; 0) {
<a name="l01855"></a>01855                 <span class="keywordflow">return</span> -1;
<a name="l01856"></a>01856         }
<a name="l01857"></a>01857 
<a name="l01858"></a>01858         <span class="comment">/*</span>
<a name="l01859"></a>01859 <span class="comment">        * Special case - no rounding</span>
<a name="l01860"></a>01860 <span class="comment">        */</span>
<a name="l01861"></a>01861         <span class="keywordflow">if</span> (rad == 0) {
<a name="l01862"></a>01862                 <span class="keywordflow">return</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a6ab25c393f6e5f8d68ea3365f6ea98d2" title="Draw rectangle with blending.">rectangleColor</a>(dst, x1, y1, x2, y2, color);
<a name="l01863"></a>01863         }
<a name="l01864"></a>01864 
<a name="l01865"></a>01865         <span class="comment">/*</span>
<a name="l01866"></a>01866 <span class="comment">        * Check visibility of clipping rectangle</span>
<a name="l01867"></a>01867 <span class="comment">        */</span>
<a name="l01868"></a>01868         <span class="keywordflow">if</span> ((dst-&gt;clip_rect.w==0) || (dst-&gt;clip_rect.h==0)) {
<a name="l01869"></a>01869                 <span class="keywordflow">return</span> 0;
<a name="l01870"></a>01870         }
<a name="l01871"></a>01871 
<a name="l01872"></a>01872         <span class="comment">/*</span>
<a name="l01873"></a>01873 <span class="comment">        * Test for special cases of straight lines or single point </span>
<a name="l01874"></a>01874 <span class="comment">        */</span>
<a name="l01875"></a>01875         <span class="keywordflow">if</span> (x1 == x2) {
<a name="l01876"></a>01876                 <span class="keywordflow">if</span> (y1 == y2) {
<a name="l01877"></a>01877                         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ae6f8690e5c5a85d3263c8e16727b34ef" title="Pixel draw with blending enabled if a&lt;255.">pixelColor</a>(dst, x1, y1, color));
<a name="l01878"></a>01878                 } <span class="keywordflow">else</span> {
<a name="l01879"></a>01879                         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a9b45060155a19fee24f998d7790f1d67" title="Draw vertical line with blending.">vlineColor</a>(dst, x1, y1, y2, color));
<a name="l01880"></a>01880                 }
<a name="l01881"></a>01881         } <span class="keywordflow">else</span> {
<a name="l01882"></a>01882                 <span class="keywordflow">if</span> (y1 == y2) {
<a name="l01883"></a>01883                         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, x1, x2, y1, color));
<a name="l01884"></a>01884                 }
<a name="l01885"></a>01885         }
<a name="l01886"></a>01886 
<a name="l01887"></a>01887         <span class="comment">/*</span>
<a name="l01888"></a>01888 <span class="comment">        * Swap x1, x2 if required </span>
<a name="l01889"></a>01889 <span class="comment">        */</span>
<a name="l01890"></a>01890         <span class="keywordflow">if</span> (x1 &gt; x2) {
<a name="l01891"></a>01891                 tmp = x1;
<a name="l01892"></a>01892                 x1 = x2;
<a name="l01893"></a>01893                 x2 = tmp;
<a name="l01894"></a>01894         }
<a name="l01895"></a>01895 
<a name="l01896"></a>01896         <span class="comment">/*</span>
<a name="l01897"></a>01897 <span class="comment">        * Swap y1, y2 if required </span>
<a name="l01898"></a>01898 <span class="comment">        */</span>
<a name="l01899"></a>01899         <span class="keywordflow">if</span> (y1 &gt; y2) {
<a name="l01900"></a>01900                 tmp = y1;
<a name="l01901"></a>01901                 y1 = y2;
<a name="l01902"></a>01902                 y2 = tmp;
<a name="l01903"></a>01903         }
<a name="l01904"></a>01904 
<a name="l01905"></a>01905         <span class="comment">/*</span>
<a name="l01906"></a>01906 <span class="comment">        * Calculate width&amp;height </span>
<a name="l01907"></a>01907 <span class="comment">        */</span>
<a name="l01908"></a>01908         w = x2 - x1;
<a name="l01909"></a>01909         h = y2 - y1;
<a name="l01910"></a>01910 
<a name="l01911"></a>01911         <span class="comment">/*</span>
<a name="l01912"></a>01912 <span class="comment">        * Maybe adjust radius</span>
<a name="l01913"></a>01913 <span class="comment">        */</span>
<a name="l01914"></a>01914         <span class="keywordflow">if</span> ((rad * 2) &gt; w)  
<a name="l01915"></a>01915         {
<a name="l01916"></a>01916                 rad = w / 2;
<a name="l01917"></a>01917         }
<a name="l01918"></a>01918         <span class="keywordflow">if</span> ((rad * 2) &gt; h)
<a name="l01919"></a>01919         {
<a name="l01920"></a>01920                 rad = h / 2;
<a name="l01921"></a>01921         }
<a name="l01922"></a>01922 
<a name="l01923"></a>01923         <span class="comment">/*</span>
<a name="l01924"></a>01924 <span class="comment">        * Draw corners</span>
<a name="l01925"></a>01925 <span class="comment">        */</span>
<a name="l01926"></a>01926         result = 0;
<a name="l01927"></a>01927         xx1 = x1 + rad;
<a name="l01928"></a>01928         xx2 = x2 - rad;
<a name="l01929"></a>01929         yy1 = y1 + rad;
<a name="l01930"></a>01930         yy2 = y2 - rad;
<a name="l01931"></a>01931         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a2c30ee985b2513dc58d9b19d4e71562b" title="Draw filled pie with alpha blending.">filledPieColor</a>(dst, xx1, yy1, rad, 180, 270, color);
<a name="l01932"></a>01932         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a2c30ee985b2513dc58d9b19d4e71562b" title="Draw filled pie with alpha blending.">filledPieColor</a>(dst, xx2, yy1, rad, 270, 360, color);
<a name="l01933"></a>01933         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a2c30ee985b2513dc58d9b19d4e71562b" title="Draw filled pie with alpha blending.">filledPieColor</a>(dst, xx1, yy2, rad,  90, 180, color);
<a name="l01934"></a>01934         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a2c30ee985b2513dc58d9b19d4e71562b" title="Draw filled pie with alpha blending.">filledPieColor</a>(dst, xx2, yy2, rad,   0,  90, color);
<a name="l01935"></a>01935 
<a name="l01936"></a>01936         <span class="comment">/*</span>
<a name="l01937"></a>01937 <span class="comment">        * Draw body</span>
<a name="l01938"></a>01938 <span class="comment">        */</span>
<a name="l01939"></a>01939         xx1++;
<a name="l01940"></a>01940         xx2--;
<a name="l01941"></a>01941         yy1++;
<a name="l01942"></a>01942         yy2--;
<a name="l01943"></a>01943         <span class="keywordflow">if</span> (xx1 &lt;= xx2) {
<a name="l01944"></a>01944                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a6bb30dfc32d0aee20271a0356a2e2fd0" title="Draw box (filled rectangle) with blending.">boxColor</a>(dst, xx1, y1, xx2, y2, color);
<a name="l01945"></a>01945         }
<a name="l01946"></a>01946         <span class="keywordflow">if</span> (yy1 &lt;= yy2) {
<a name="l01947"></a>01947                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a6bb30dfc32d0aee20271a0356a2e2fd0" title="Draw box (filled rectangle) with blending.">boxColor</a>(dst, x1, yy1, xx1-1, yy2, color);
<a name="l01948"></a>01948                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a6bb30dfc32d0aee20271a0356a2e2fd0" title="Draw box (filled rectangle) with blending.">boxColor</a>(dst, xx2+1, yy1, x2, yy2, color);
<a name="l01949"></a>01949         }
<a name="l01950"></a>01950 
<a name="l01951"></a>01951         <span class="keywordflow">return</span> result;
<a name="l01952"></a>01952 }
<a name="l01953"></a>01953 
<a name="l01970"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a7105b88e62fe42b26602d3b426547bc7">01970</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#aad706348fec18631d7bc48a2d91f5b4d" title="Draw rounded-corner box (filled rectangle) with blending.">roundedBoxRGBA</a>(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2,
<a name="l01971"></a>01971         Sint16 y2, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l01972"></a>01972 {
<a name="l01973"></a>01973         <span class="comment">/*</span>
<a name="l01974"></a>01974 <span class="comment">        * Draw </span>
<a name="l01975"></a>01975 <span class="comment">        */</span>
<a name="l01976"></a>01976         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a718c4f31d1e145106959c2a77d5fee9d" title="Draw rounded-corner box (filled rectangle) with blending.">roundedBoxColor</a>
<a name="l01977"></a>01977                 (dst, x1, y1, x2, y2, rad, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a));
<a name="l01978"></a>01978 }
<a name="l01979"></a>01979 
<a name="l01980"></a>01980 <span class="comment">/* --------- Clipping routines for line */</span>
<a name="l01981"></a>01981 
<a name="l01982"></a>01982 <span class="comment">/* Clipping based heavily on code from                       */</span>
<a name="l01983"></a>01983 <span class="comment">/* http://www.ncsa.uiuc.edu/Vis/Graphics/src/clipCohSuth.c   */</span>
<a name="l01984"></a>01984 
<a name="l01985"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#ac7260a99c00538400ab4be67304ad36c">01985</a> <span class="preprocessor">#define CLIP_LEFT_EDGE   0x1</span>
<a name="l01986"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#a0f5e2b2e79afa32c688c77f776a84308">01986</a> <span class="preprocessor"></span><span class="preprocessor">#define CLIP_RIGHT_EDGE  0x2</span>
<a name="l01987"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#ae4fa529c5f9a39310b98769cdb007c2d">01987</a> <span class="preprocessor"></span><span class="preprocessor">#define CLIP_BOTTOM_EDGE 0x4</span>
<a name="l01988"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#acd233fdea48722eb128c4c48f619a605">01988</a> <span class="preprocessor"></span><span class="preprocessor">#define CLIP_TOP_EDGE    0x8</span>
<a name="l01989"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#a3f497d83ed5f593a5bc56c2ba7e13f5b">01989</a> <span class="preprocessor"></span><span class="preprocessor">#define CLIP_INSIDE(a)   (!a)</span>
<a name="l01990"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#ac1e60af8e37b6b372dcfd2d88299b662">01990</a> <span class="preprocessor"></span><span class="preprocessor">#define CLIP_REJECT(a,b) (a&amp;b)</span>
<a name="l01991"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#a004c35133422cb574c41bb114d4592c6">01991</a> <span class="preprocessor"></span><span class="preprocessor">#define CLIP_ACCEPT(a,b) (!(a|b))</span>
<a name="l01992"></a>01992 <span class="preprocessor"></span>
<a name="l02005"></a>02005 <span class="keyword">static</span> <span class="keywordtype">int</span> _clipEncode(Sint16 x, Sint16 y, Sint16 left, Sint16 top, Sint16 right, Sint16 bottom)
<a name="l02006"></a>02006 {
<a name="l02007"></a>02007         <span class="keywordtype">int</span> code = 0;
<a name="l02008"></a>02008 
<a name="l02009"></a>02009         <span class="keywordflow">if</span> (x &lt; left) {
<a name="l02010"></a>02010                 code |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac7260a99c00538400ab4be67304ad36c">CLIP_LEFT_EDGE</a>;
<a name="l02011"></a>02011         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (x &gt; right) {
<a name="l02012"></a>02012                 code |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a0f5e2b2e79afa32c688c77f776a84308">CLIP_RIGHT_EDGE</a>;
<a name="l02013"></a>02013         }
<a name="l02014"></a>02014         <span class="keywordflow">if</span> (y &lt; top) {
<a name="l02015"></a>02015                 code |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#acd233fdea48722eb128c4c48f619a605">CLIP_TOP_EDGE</a>;
<a name="l02016"></a>02016         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (y &gt; bottom) {
<a name="l02017"></a>02017                 code |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae4fa529c5f9a39310b98769cdb007c2d">CLIP_BOTTOM_EDGE</a>;
<a name="l02018"></a>02018         }
<a name="l02019"></a>02019         <span class="keywordflow">return</span> code;
<a name="l02020"></a>02020 }
<a name="l02021"></a>02021 
<a name="l02031"></a>02031 <span class="keyword">static</span> <span class="keywordtype">int</span> _clipLine(SDL_Surface * dst, Sint16 * x1, Sint16 * y1, Sint16 * x2, Sint16 * y2)
<a name="l02032"></a>02032 {
<a name="l02033"></a>02033         Sint16 left, right, top, bottom;
<a name="l02034"></a>02034         <span class="keywordtype">int</span> code1, code2;
<a name="l02035"></a>02035         <span class="keywordtype">int</span> draw = 0;
<a name="l02036"></a>02036         Sint16 swaptmp;
<a name="l02037"></a>02037         <span class="keywordtype">float</span> m;
<a name="l02038"></a>02038 
<a name="l02039"></a>02039         <span class="comment">/*</span>
<a name="l02040"></a>02040 <span class="comment">        * Get clipping boundary </span>
<a name="l02041"></a>02041 <span class="comment">        */</span>
<a name="l02042"></a>02042         left = dst-&gt;clip_rect.x;
<a name="l02043"></a>02043         right = dst-&gt;clip_rect.x + dst-&gt;clip_rect.w - 1;
<a name="l02044"></a>02044         top = dst-&gt;clip_rect.y;
<a name="l02045"></a>02045         bottom = dst-&gt;clip_rect.y + dst-&gt;clip_rect.h - 1;
<a name="l02046"></a>02046 
<a name="l02047"></a>02047         <span class="keywordflow">while</span> (1) {
<a name="l02048"></a>02048                 code1 = _clipEncode(*x1, *y1, left, top, right, bottom);
<a name="l02049"></a>02049                 code2 = _clipEncode(*x2, *y2, left, top, right, bottom);
<a name="l02050"></a>02050                 <span class="keywordflow">if</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a004c35133422cb574c41bb114d4592c6">CLIP_ACCEPT</a>(code1, code2)) {
<a name="l02051"></a>02051                         draw = 1;
<a name="l02052"></a>02052                         <span class="keywordflow">break</span>;
<a name="l02053"></a>02053                 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ac1e60af8e37b6b372dcfd2d88299b662">CLIP_REJECT</a>(code1, code2))
<a name="l02054"></a>02054                         <span class="keywordflow">break</span>;
<a name="l02055"></a>02055                 <span class="keywordflow">else</span> {
<a name="l02056"></a>02056                         <span class="keywordflow">if</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a3f497d83ed5f593a5bc56c2ba7e13f5b">CLIP_INSIDE</a>(code1)) {
<a name="l02057"></a>02057                                 swaptmp = *x2;
<a name="l02058"></a>02058                                 *x2 = *x1;
<a name="l02059"></a>02059                                 *x1 = swaptmp;
<a name="l02060"></a>02060                                 swaptmp = *y2;
<a name="l02061"></a>02061                                 *y2 = *y1;
<a name="l02062"></a>02062                                 *y1 = swaptmp;
<a name="l02063"></a>02063                                 swaptmp = code2;
<a name="l02064"></a>02064                                 code2 = code1;
<a name="l02065"></a>02065                                 code1 = swaptmp;
<a name="l02066"></a>02066                         }
<a name="l02067"></a>02067                         <span class="keywordflow">if</span> (*x2 != *x1) {
<a name="l02068"></a>02068                                 m = (float)(*y2 - *y1) / (float)(*x2 - *x1);
<a name="l02069"></a>02069                         } <span class="keywordflow">else</span> {
<a name="l02070"></a>02070                                 m = 1.0f;
<a name="l02071"></a>02071                         }
<a name="l02072"></a>02072                         <span class="keywordflow">if</span> (code1 &amp; <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac7260a99c00538400ab4be67304ad36c">CLIP_LEFT_EDGE</a>) {
<a name="l02073"></a>02073                                 *y1 += (Sint16) ((left - *x1) * m);
<a name="l02074"></a>02074                                 *x1 = left;
<a name="l02075"></a>02075                         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (code1 &amp; <a class="code" href="_s_d_l__gfx_primitives_8c.html#a0f5e2b2e79afa32c688c77f776a84308">CLIP_RIGHT_EDGE</a>) {
<a name="l02076"></a>02076                                 *y1 += (Sint16) ((right - *x1) * m);
<a name="l02077"></a>02077                                 *x1 = right;
<a name="l02078"></a>02078                         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (code1 &amp; <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae4fa529c5f9a39310b98769cdb007c2d">CLIP_BOTTOM_EDGE</a>) {
<a name="l02079"></a>02079                                 <span class="keywordflow">if</span> (*x2 != *x1) {
<a name="l02080"></a>02080                                         *x1 += (Sint16) ((bottom - *y1) / m);
<a name="l02081"></a>02081                                 }
<a name="l02082"></a>02082                                 *y1 = bottom;
<a name="l02083"></a>02083                         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (code1 &amp; <a class="code" href="_s_d_l__gfx_primitives_8c.html#acd233fdea48722eb128c4c48f619a605">CLIP_TOP_EDGE</a>) {
<a name="l02084"></a>02084                                 <span class="keywordflow">if</span> (*x2 != *x1) {
<a name="l02085"></a>02085                                         *x1 += (Sint16) ((top - *y1) / m);
<a name="l02086"></a>02086                                 }
<a name="l02087"></a>02087                                 *y1 = top;
<a name="l02088"></a>02088                         }
<a name="l02089"></a>02089                 }
<a name="l02090"></a>02090         }
<a name="l02091"></a>02091 
<a name="l02092"></a>02092         <span class="keywordflow">return</span> draw;
<a name="l02093"></a>02093 }
<a name="l02094"></a>02094 
<a name="l02107"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a16693489da67d6e65a28f9e5217b46f9">02107</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a6bb30dfc32d0aee20271a0356a2e2fd0" title="Draw box (filled rectangle) with blending.">boxColor</a>(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color)
<a name="l02108"></a>02108 {
<a name="l02109"></a>02109         Sint16 left, right, top, bottom;
<a name="l02110"></a>02110         Uint8 *pixel, *pixellast;
<a name="l02111"></a>02111         <span class="keywordtype">int</span> x, dx;
<a name="l02112"></a>02112         <span class="keywordtype">int</span> dy;
<a name="l02113"></a>02113         <span class="keywordtype">int</span> pixx, pixy;
<a name="l02114"></a>02114         Sint16 w, h, tmp;
<a name="l02115"></a>02115         <span class="keywordtype">int</span> result;
<a name="l02116"></a>02116         Uint8 *colorptr;
<a name="l02117"></a>02117 
<a name="l02118"></a>02118         <span class="comment">/*</span>
<a name="l02119"></a>02119 <span class="comment">        * Check visibility of clipping rectangle</span>
<a name="l02120"></a>02120 <span class="comment">        */</span>
<a name="l02121"></a>02121         <span class="keywordflow">if</span> ((dst-&gt;clip_rect.w==0) || (dst-&gt;clip_rect.h==0)) {
<a name="l02122"></a>02122                 <span class="keywordflow">return</span>(0);
<a name="l02123"></a>02123         }
<a name="l02124"></a>02124 
<a name="l02125"></a>02125         <span class="comment">/*</span>
<a name="l02126"></a>02126 <span class="comment">        * Order coordinates to ensure that</span>
<a name="l02127"></a>02127 <span class="comment">        * x1&lt;=x2 and y1&lt;=y2 </span>
<a name="l02128"></a>02128 <span class="comment">        */</span>
<a name="l02129"></a>02129         <span class="keywordflow">if</span> (x1 &gt; x2) {
<a name="l02130"></a>02130                 tmp = x1;
<a name="l02131"></a>02131                 x1 = x2;
<a name="l02132"></a>02132                 x2 = tmp;
<a name="l02133"></a>02133         }
<a name="l02134"></a>02134         <span class="keywordflow">if</span> (y1 &gt; y2) {
<a name="l02135"></a>02135                 tmp = y1;
<a name="l02136"></a>02136                 y1 = y2;
<a name="l02137"></a>02137                 y2 = tmp;
<a name="l02138"></a>02138         }
<a name="l02139"></a>02139 
<a name="l02140"></a>02140         <span class="comment">/* </span>
<a name="l02141"></a>02141 <span class="comment">        * Get clipping boundary and </span>
<a name="l02142"></a>02142 <span class="comment">        * check visibility </span>
<a name="l02143"></a>02143 <span class="comment">        */</span>
<a name="l02144"></a>02144         left = dst-&gt;clip_rect.x;
<a name="l02145"></a>02145         <span class="keywordflow">if</span> (x2&lt;left) {
<a name="l02146"></a>02146                 <span class="keywordflow">return</span>(0);
<a name="l02147"></a>02147         }
<a name="l02148"></a>02148         right = dst-&gt;clip_rect.x + dst-&gt;clip_rect.w - 1;
<a name="l02149"></a>02149         <span class="keywordflow">if</span> (x1&gt;right) {
<a name="l02150"></a>02150                 <span class="keywordflow">return</span>(0);
<a name="l02151"></a>02151         }
<a name="l02152"></a>02152         top = dst-&gt;clip_rect.y;
<a name="l02153"></a>02153         <span class="keywordflow">if</span> (y2&lt;top) {
<a name="l02154"></a>02154                 <span class="keywordflow">return</span>(0);
<a name="l02155"></a>02155         }
<a name="l02156"></a>02156         bottom = dst-&gt;clip_rect.y + dst-&gt;clip_rect.h - 1;
<a name="l02157"></a>02157         <span class="keywordflow">if</span> (y1&gt;bottom) {
<a name="l02158"></a>02158                 <span class="keywordflow">return</span>(0);
<a name="l02159"></a>02159         }
<a name="l02160"></a>02160 
<a name="l02161"></a>02161         <span class="comment">/* Clip all points */</span>
<a name="l02162"></a>02162         <span class="keywordflow">if</span> (x1&lt;left) { 
<a name="l02163"></a>02163                 x1=left; 
<a name="l02164"></a>02164         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (x1&gt;right) {
<a name="l02165"></a>02165                 x1=right;
<a name="l02166"></a>02166         }
<a name="l02167"></a>02167         <span class="keywordflow">if</span> (x2&lt;left) { 
<a name="l02168"></a>02168                 x2=left; 
<a name="l02169"></a>02169         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (x2&gt;right) {
<a name="l02170"></a>02170                 x2=right;
<a name="l02171"></a>02171         }
<a name="l02172"></a>02172         <span class="keywordflow">if</span> (y1&lt;top) { 
<a name="l02173"></a>02173                 y1=top; 
<a name="l02174"></a>02174         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (y1&gt;bottom) {
<a name="l02175"></a>02175                 y1=bottom;
<a name="l02176"></a>02176         }
<a name="l02177"></a>02177         <span class="keywordflow">if</span> (y2&lt;top) { 
<a name="l02178"></a>02178                 y2=top; 
<a name="l02179"></a>02179         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (y2&gt;bottom) {
<a name="l02180"></a>02180                 y2=bottom;
<a name="l02181"></a>02181         }
<a name="l02182"></a>02182 
<a name="l02183"></a>02183         <span class="comment">/*</span>
<a name="l02184"></a>02184 <span class="comment">        * Test for special cases of straight line or single point </span>
<a name="l02185"></a>02185 <span class="comment">        */</span>
<a name="l02186"></a>02186         <span class="keywordflow">if</span> (x1 == x2) {
<a name="l02187"></a>02187                 <span class="keywordflow">if</span> (y1 == y2) {
<a name="l02188"></a>02188                         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ae6f8690e5c5a85d3263c8e16727b34ef" title="Pixel draw with blending enabled if a&lt;255.">pixelColor</a>(dst, x1, y1, color));
<a name="l02189"></a>02189                 } <span class="keywordflow">else</span> { 
<a name="l02190"></a>02190                         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a9b45060155a19fee24f998d7790f1d67" title="Draw vertical line with blending.">vlineColor</a>(dst, x1, y1, y2, color));
<a name="l02191"></a>02191                 }
<a name="l02192"></a>02192         }
<a name="l02193"></a>02193         <span class="keywordflow">if</span> (y1 == y2) {
<a name="l02194"></a>02194                 <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, x1, x2, y1, color));
<a name="l02195"></a>02195         }
<a name="l02196"></a>02196 
<a name="l02197"></a>02197         <span class="comment">/*</span>
<a name="l02198"></a>02198 <span class="comment">        * Calculate width&amp;height </span>
<a name="l02199"></a>02199 <span class="comment">        */</span>
<a name="l02200"></a>02200         w = x2 - x1;
<a name="l02201"></a>02201         h = y2 - y1;
<a name="l02202"></a>02202 
<a name="l02203"></a>02203         <span class="comment">/*</span>
<a name="l02204"></a>02204 <span class="comment">        * Alpha check </span>
<a name="l02205"></a>02205 <span class="comment">        */</span>
<a name="l02206"></a>02206         <span class="keywordflow">if</span> ((color &amp; 255) == 255) {
<a name="l02207"></a>02207 
<a name="l02208"></a>02208                 <span class="comment">/*</span>
<a name="l02209"></a>02209 <span class="comment">                * No alpha-blending required </span>
<a name="l02210"></a>02210 <span class="comment">                */</span>
<a name="l02211"></a>02211 
<a name="l02212"></a>02212                 <span class="comment">/*</span>
<a name="l02213"></a>02213 <span class="comment">                * Setup color </span>
<a name="l02214"></a>02214 <span class="comment">                */</span>
<a name="l02215"></a>02215                 colorptr = (Uint8 *) &amp; color;
<a name="l02216"></a>02216                 <span class="keywordflow">if</span> (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
<a name="l02217"></a>02217                         color = SDL_MapRGBA(dst-&gt;format, colorptr[0], colorptr[1], colorptr[2], colorptr[3]);
<a name="l02218"></a>02218                 } <span class="keywordflow">else</span> {
<a name="l02219"></a>02219                         color = SDL_MapRGBA(dst-&gt;format, colorptr[3], colorptr[2], colorptr[1], colorptr[0]);
<a name="l02220"></a>02220                 }
<a name="l02221"></a>02221 
<a name="l02222"></a>02222                 <span class="comment">/*</span>
<a name="l02223"></a>02223 <span class="comment">                * Lock the surface </span>
<a name="l02224"></a>02224 <span class="comment">                */</span>
<a name="l02225"></a>02225                 <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l02226"></a>02226                         <span class="keywordflow">if</span> (SDL_LockSurface(dst) &lt; 0) {
<a name="l02227"></a>02227                                 <span class="keywordflow">return</span> (-1);
<a name="l02228"></a>02228                         }
<a name="l02229"></a>02229                 }
<a name="l02230"></a>02230 
<a name="l02231"></a>02231                 <span class="comment">/*</span>
<a name="l02232"></a>02232 <span class="comment">                * More variable setup </span>
<a name="l02233"></a>02233 <span class="comment">                */</span>
<a name="l02234"></a>02234                 dx = w;
<a name="l02235"></a>02235                 dy = h;
<a name="l02236"></a>02236                 pixx = dst-&gt;format-&gt;BytesPerPixel;
<a name="l02237"></a>02237                 pixy = dst-&gt;pitch;
<a name="l02238"></a>02238                 pixel = ((Uint8 *) dst-&gt;pixels) + pixx * (int) x1 + pixy * (<span class="keywordtype">int</span>) y1;
<a name="l02239"></a>02239                 pixellast = pixel + pixx * dx + pixy * dy;
<a name="l02240"></a>02240                 dx++;
<a name="l02241"></a>02241 
<a name="l02242"></a>02242                 <span class="comment">/*</span>
<a name="l02243"></a>02243 <span class="comment">                * Draw </span>
<a name="l02244"></a>02244 <span class="comment">                */</span>
<a name="l02245"></a>02245                 <span class="keywordflow">switch</span> (dst-&gt;format-&gt;BytesPerPixel) {
<a name="l02246"></a>02246                 <span class="keywordflow">case</span> 1:
<a name="l02247"></a>02247                         <span class="keywordflow">for</span> (; pixel &lt;= pixellast; pixel += pixy) {
<a name="l02248"></a>02248                                 memset(pixel, (Uint8) color, dx);
<a name="l02249"></a>02249                         }
<a name="l02250"></a>02250                         <span class="keywordflow">break</span>;
<a name="l02251"></a>02251                 <span class="keywordflow">case</span> 2:
<a name="l02252"></a>02252                         pixy -= (pixx * dx);
<a name="l02253"></a>02253                         <span class="keywordflow">for</span> (; pixel &lt;= pixellast; pixel += pixy) {
<a name="l02254"></a>02254                                 <span class="keywordflow">for</span> (x = 0; x &lt; dx; x++) {
<a name="l02255"></a>02255                                         *(Uint16*) pixel = color;
<a name="l02256"></a>02256                                         pixel += pixx;
<a name="l02257"></a>02257                                 }
<a name="l02258"></a>02258                         }
<a name="l02259"></a>02259                         <span class="keywordflow">break</span>;
<a name="l02260"></a>02260                 <span class="keywordflow">case</span> 3:
<a name="l02261"></a>02261                         pixy -= (pixx * dx);
<a name="l02262"></a>02262                         <span class="keywordflow">for</span> (; pixel &lt;= pixellast; pixel += pixy) {
<a name="l02263"></a>02263                                 <span class="keywordflow">for</span> (x = 0; x &lt; dx; x++) {
<a name="l02264"></a>02264                                         <span class="keywordflow">if</span> (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
<a name="l02265"></a>02265                                                 pixel[0] = (color &gt;&gt; 16) &amp; 0xff;
<a name="l02266"></a>02266                                                 pixel[1] = (color &gt;&gt; 8) &amp; 0xff;
<a name="l02267"></a>02267                                                 pixel[2] = color &amp; 0xff;
<a name="l02268"></a>02268                                         } <span class="keywordflow">else</span> {
<a name="l02269"></a>02269                                                 pixel[0] = color &amp; 0xff;
<a name="l02270"></a>02270                                                 pixel[1] = (color &gt;&gt; 8) &amp; 0xff;
<a name="l02271"></a>02271                                                 pixel[2] = (color &gt;&gt; 16) &amp; 0xff;
<a name="l02272"></a>02272                                         }
<a name="l02273"></a>02273                                         pixel += pixx;
<a name="l02274"></a>02274                                 }
<a name="l02275"></a>02275                         }
<a name="l02276"></a>02276                         <span class="keywordflow">break</span>;
<a name="l02277"></a>02277                 <span class="keywordflow">default</span>:                <span class="comment">/* case 4 */</span>
<a name="l02278"></a>02278                         pixy -= (pixx * dx);
<a name="l02279"></a>02279                         <span class="keywordflow">for</span> (; pixel &lt;= pixellast; pixel += pixy) {
<a name="l02280"></a>02280                                 <span class="keywordflow">for</span> (x = 0; x &lt; dx; x++) {
<a name="l02281"></a>02281                                         *(Uint32 *) pixel = color;
<a name="l02282"></a>02282                                         pixel += pixx;
<a name="l02283"></a>02283                                 }
<a name="l02284"></a>02284                         }
<a name="l02285"></a>02285                         <span class="keywordflow">break</span>;
<a name="l02286"></a>02286                 }
<a name="l02287"></a>02287 
<a name="l02288"></a>02288                 <span class="comment">/* Unlock surface */</span>
<a name="l02289"></a>02289                 <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l02290"></a>02290                         SDL_UnlockSurface(dst);
<a name="l02291"></a>02291                 }
<a name="l02292"></a>02292 
<a name="l02293"></a>02293                 result = 0;
<a name="l02294"></a>02294 
<a name="l02295"></a>02295         } <span class="keywordflow">else</span> {
<a name="l02296"></a>02296 
<a name="l02297"></a>02297                 result = <a class="code" href="_s_d_l__gfx_primitives_8c.html#ace9f2505c12c5dacc778509991cd3716" title="Draw filled rectangle of RGBA color with alpha blending.">filledRectAlpha</a>(dst, x1, y1, x1 + w, y1 + h, color);
<a name="l02298"></a>02298 
<a name="l02299"></a>02299         }
<a name="l02300"></a>02300 
<a name="l02301"></a>02301         <span class="keywordflow">return</span> (result);
<a name="l02302"></a>02302 }
<a name="l02303"></a>02303 
<a name="l02319"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a0ae084c90bd9b734356ad723d45973c8">02319</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a1864b3062793a7f7dd81aaf8c8abd6b0" title="Draw box (filled rectangle) with blending.">boxRGBA</a>(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l02320"></a>02320 {
<a name="l02321"></a>02321         <span class="comment">/*</span>
<a name="l02322"></a>02322 <span class="comment">        * Draw </span>
<a name="l02323"></a>02323 <span class="comment">        */</span>
<a name="l02324"></a>02324         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a6bb30dfc32d0aee20271a0356a2e2fd0" title="Draw box (filled rectangle) with blending.">boxColor</a>(dst, x1, y1, x2, y2, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a));
<a name="l02325"></a>02325 }
<a name="l02326"></a>02326 
<a name="l02327"></a>02327 <span class="comment">/* ----- Line */</span>
<a name="l02328"></a>02328 
<a name="l02329"></a>02329 <span class="comment">/* Non-alpha line drawing code adapted from routine          */</span>
<a name="l02330"></a>02330 <span class="comment">/* by Pete Shinners, pete@shinners.org                       */</span>
<a name="l02331"></a>02331 <span class="comment">/* Originally from pygame, http://pygame.seul.org            */</span>
<a name="l02332"></a>02332 
<a name="l02333"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#ae2f08dc603ae93c402abd918ba4e23e1">02333</a> <span class="preprocessor">#define ABS(a) (((a)&lt;0) ? -(a) : (a))</span>
<a name="l02334"></a>02334 <span class="preprocessor"></span>
<a name="l02347"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a6f37058aed308619de8109ebe84b5fe9">02347</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#ad44c550fab3cb736eb049713ede94052" title="Draw line with alpha blending.">lineColor</a>(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color)
<a name="l02348"></a>02348 {
<a name="l02349"></a>02349         <span class="keywordtype">int</span> pixx, pixy;
<a name="l02350"></a>02350         <span class="keywordtype">int</span> x, y;
<a name="l02351"></a>02351         <span class="keywordtype">int</span> dx, dy;
<a name="l02352"></a>02352         <span class="keywordtype">int</span> ax, ay;
<a name="l02353"></a>02353         <span class="keywordtype">int</span> sx, sy;
<a name="l02354"></a>02354         <span class="keywordtype">int</span> swaptmp;
<a name="l02355"></a>02355         Uint8 *pixel;
<a name="l02356"></a>02356         Uint8 *colorptr;
<a name="l02357"></a>02357 
<a name="l02358"></a>02358         <span class="comment">/*</span>
<a name="l02359"></a>02359 <span class="comment">        * Clip line and test if we have to draw </span>
<a name="l02360"></a>02360 <span class="comment">        */</span>
<a name="l02361"></a>02361         <span class="keywordflow">if</span> (!(_clipLine(dst, &amp;x1, &amp;y1, &amp;x2, &amp;y2))) {
<a name="l02362"></a>02362                 <span class="keywordflow">return</span> (0);
<a name="l02363"></a>02363         }
<a name="l02364"></a>02364 
<a name="l02365"></a>02365         <span class="comment">/*</span>
<a name="l02366"></a>02366 <span class="comment">        * Test for special cases of straight lines or single point </span>
<a name="l02367"></a>02367 <span class="comment">        */</span>
<a name="l02368"></a>02368         <span class="keywordflow">if</span> (x1 == x2) {
<a name="l02369"></a>02369                 <span class="keywordflow">if</span> (y1 &lt; y2) {
<a name="l02370"></a>02370                         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a9b45060155a19fee24f998d7790f1d67" title="Draw vertical line with blending.">vlineColor</a>(dst, x1, y1, y2, color));
<a name="l02371"></a>02371                 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (y1 &gt; y2) {
<a name="l02372"></a>02372                         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a9b45060155a19fee24f998d7790f1d67" title="Draw vertical line with blending.">vlineColor</a>(dst, x1, y2, y1, color));
<a name="l02373"></a>02373                 } <span class="keywordflow">else</span> {
<a name="l02374"></a>02374                         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ae6f8690e5c5a85d3263c8e16727b34ef" title="Pixel draw with blending enabled if a&lt;255.">pixelColor</a>(dst, x1, y1, color));
<a name="l02375"></a>02375                 }
<a name="l02376"></a>02376         }
<a name="l02377"></a>02377         <span class="keywordflow">if</span> (y1 == y2) {
<a name="l02378"></a>02378                 <span class="keywordflow">if</span> (x1 &lt; x2) {
<a name="l02379"></a>02379                         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, x1, x2, y1, color));
<a name="l02380"></a>02380                 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (x1 &gt; x2) {
<a name="l02381"></a>02381                         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, x2, x1, y1, color));
<a name="l02382"></a>02382                 }
<a name="l02383"></a>02383         }
<a name="l02384"></a>02384 
<a name="l02385"></a>02385         <span class="comment">/*</span>
<a name="l02386"></a>02386 <span class="comment">        * Variable setup </span>
<a name="l02387"></a>02387 <span class="comment">        */</span>
<a name="l02388"></a>02388         dx = x2 - x1;
<a name="l02389"></a>02389         dy = y2 - y1;
<a name="l02390"></a>02390         sx = (dx &gt;= 0) ? 1 : -1;
<a name="l02391"></a>02391         sy = (dy &gt;= 0) ? 1 : -1;
<a name="l02392"></a>02392 
<a name="l02393"></a>02393         <span class="comment">/* Lock surface */</span>
<a name="l02394"></a>02394         <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l02395"></a>02395                 <span class="keywordflow">if</span> (SDL_LockSurface(dst) &lt; 0) {
<a name="l02396"></a>02396                         <span class="keywordflow">return</span> (-1);
<a name="l02397"></a>02397                 }
<a name="l02398"></a>02398         }
<a name="l02399"></a>02399 
<a name="l02400"></a>02400         <span class="comment">/*</span>
<a name="l02401"></a>02401 <span class="comment">        * Check for alpha blending </span>
<a name="l02402"></a>02402 <span class="comment">        */</span>
<a name="l02403"></a>02403         <span class="keywordflow">if</span> ((color &amp; 255) == 255) {
<a name="l02404"></a>02404 
<a name="l02405"></a>02405                 <span class="comment">/*</span>
<a name="l02406"></a>02406 <span class="comment">                * No alpha blending - use fast pixel routines </span>
<a name="l02407"></a>02407 <span class="comment">                */</span>
<a name="l02408"></a>02408 
<a name="l02409"></a>02409                 <span class="comment">/*</span>
<a name="l02410"></a>02410 <span class="comment">                * Setup color </span>
<a name="l02411"></a>02411 <span class="comment">                */</span>
<a name="l02412"></a>02412                 colorptr = (Uint8 *) &amp; color;
<a name="l02413"></a>02413                 <span class="keywordflow">if</span> (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
<a name="l02414"></a>02414                         color = SDL_MapRGBA(dst-&gt;format, colorptr[0], colorptr[1], colorptr[2], colorptr[3]);
<a name="l02415"></a>02415                 } <span class="keywordflow">else</span> {
<a name="l02416"></a>02416                         color = SDL_MapRGBA(dst-&gt;format, colorptr[3], colorptr[2], colorptr[1], colorptr[0]);
<a name="l02417"></a>02417                 }
<a name="l02418"></a>02418 
<a name="l02419"></a>02419                 <span class="comment">/*</span>
<a name="l02420"></a>02420 <span class="comment">                * More variable setup </span>
<a name="l02421"></a>02421 <span class="comment">                */</span>
<a name="l02422"></a>02422                 dx = sx * dx + 1;
<a name="l02423"></a>02423                 dy = sy * dy + 1;
<a name="l02424"></a>02424                 pixx = dst-&gt;format-&gt;BytesPerPixel;
<a name="l02425"></a>02425                 pixy = dst-&gt;pitch;
<a name="l02426"></a>02426                 pixel = ((Uint8 *) dst-&gt;pixels) + pixx * (int) x1 + pixy * (<span class="keywordtype">int</span>) y1;
<a name="l02427"></a>02427                 pixx *= sx;
<a name="l02428"></a>02428                 pixy *= sy;
<a name="l02429"></a>02429                 <span class="keywordflow">if</span> (dx &lt; dy) {
<a name="l02430"></a>02430                         swaptmp = dx;
<a name="l02431"></a>02431                         dx = dy;
<a name="l02432"></a>02432                         dy = swaptmp;
<a name="l02433"></a>02433                         swaptmp = pixx;
<a name="l02434"></a>02434                         pixx = pixy;
<a name="l02435"></a>02435                         pixy = swaptmp;
<a name="l02436"></a>02436                 }
<a name="l02437"></a>02437 
<a name="l02438"></a>02438                 <span class="comment">/*</span>
<a name="l02439"></a>02439 <span class="comment">                * Draw </span>
<a name="l02440"></a>02440 <span class="comment">                */</span>
<a name="l02441"></a>02441                 x = 0;
<a name="l02442"></a>02442                 y = 0;
<a name="l02443"></a>02443                 <span class="keywordflow">switch</span> (dst-&gt;format-&gt;BytesPerPixel) {
<a name="l02444"></a>02444                 <span class="keywordflow">case</span> 1:
<a name="l02445"></a>02445                         <span class="keywordflow">for</span> (; x &lt; dx; x++, pixel += pixx) {
<a name="l02446"></a>02446                                 *pixel = color;
<a name="l02447"></a>02447                                 y += dy;
<a name="l02448"></a>02448                                 <span class="keywordflow">if</span> (y &gt;= dx) {
<a name="l02449"></a>02449                                         y -= dx;
<a name="l02450"></a>02450                                         pixel += pixy;
<a name="l02451"></a>02451                                 }
<a name="l02452"></a>02452                         }
<a name="l02453"></a>02453                         <span class="keywordflow">break</span>;
<a name="l02454"></a>02454                 <span class="keywordflow">case</span> 2:
<a name="l02455"></a>02455                         <span class="keywordflow">for</span> (; x &lt; dx; x++, pixel += pixx) {
<a name="l02456"></a>02456                                 *(Uint16 *) pixel = color;
<a name="l02457"></a>02457                                 y += dy;
<a name="l02458"></a>02458                                 <span class="keywordflow">if</span> (y &gt;= dx) {
<a name="l02459"></a>02459                                         y -= dx;
<a name="l02460"></a>02460                                         pixel += pixy;
<a name="l02461"></a>02461                                 }
<a name="l02462"></a>02462                         }
<a name="l02463"></a>02463                         <span class="keywordflow">break</span>;
<a name="l02464"></a>02464                 <span class="keywordflow">case</span> 3:
<a name="l02465"></a>02465                         <span class="keywordflow">for</span> (; x &lt; dx; x++, pixel += pixx) {
<a name="l02466"></a>02466                                 <span class="keywordflow">if</span> (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
<a name="l02467"></a>02467                                         pixel[0] = (color &gt;&gt; 16) &amp; 0xff;
<a name="l02468"></a>02468                                         pixel[1] = (color &gt;&gt; 8) &amp; 0xff;
<a name="l02469"></a>02469                                         pixel[2] = color &amp; 0xff;
<a name="l02470"></a>02470                                 } <span class="keywordflow">else</span> {
<a name="l02471"></a>02471                                         pixel[0] = color &amp; 0xff;
<a name="l02472"></a>02472                                         pixel[1] = (color &gt;&gt; 8) &amp; 0xff;
<a name="l02473"></a>02473                                         pixel[2] = (color &gt;&gt; 16) &amp; 0xff;
<a name="l02474"></a>02474                                 }
<a name="l02475"></a>02475                                 y += dy;
<a name="l02476"></a>02476                                 <span class="keywordflow">if</span> (y &gt;= dx) {
<a name="l02477"></a>02477                                         y -= dx;
<a name="l02478"></a>02478                                         pixel += pixy;
<a name="l02479"></a>02479                                 }
<a name="l02480"></a>02480                         }
<a name="l02481"></a>02481                         <span class="keywordflow">break</span>;
<a name="l02482"></a>02482                 <span class="keywordflow">default</span>:                <span class="comment">/* case 4 */</span>
<a name="l02483"></a>02483                         <span class="keywordflow">for</span> (; x &lt; dx; x++, pixel += pixx) {
<a name="l02484"></a>02484                                 *(Uint32 *) pixel = color;
<a name="l02485"></a>02485                                 y += dy;
<a name="l02486"></a>02486                                 <span class="keywordflow">if</span> (y &gt;= dx) {
<a name="l02487"></a>02487                                         y -= dx;
<a name="l02488"></a>02488                                         pixel += pixy;
<a name="l02489"></a>02489                                 }
<a name="l02490"></a>02490                         }
<a name="l02491"></a>02491                         <span class="keywordflow">break</span>;
<a name="l02492"></a>02492                 }
<a name="l02493"></a>02493 
<a name="l02494"></a>02494         } <span class="keywordflow">else</span> {
<a name="l02495"></a>02495 
<a name="l02496"></a>02496                 <span class="comment">/*</span>
<a name="l02497"></a>02497 <span class="comment">                * Alpha blending required - use single-pixel blits </span>
<a name="l02498"></a>02498 <span class="comment">                */</span>
<a name="l02499"></a>02499 
<a name="l02500"></a>02500                 ax = <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae2f08dc603ae93c402abd918ba4e23e1">ABS</a>(dx) &lt;&lt; 1;
<a name="l02501"></a>02501                 ay = <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae2f08dc603ae93c402abd918ba4e23e1">ABS</a>(dy) &lt;&lt; 1;
<a name="l02502"></a>02502                 x = x1;
<a name="l02503"></a>02503                 y = y1;
<a name="l02504"></a>02504                 <span class="keywordflow">if</span> (ax &gt; ay) {
<a name="l02505"></a>02505                         <span class="keywordtype">int</span> d = ay - (ax &gt;&gt; 1);
<a name="l02506"></a>02506 
<a name="l02507"></a>02507                         <span class="keywordflow">while</span> (x != x2) {
<a name="l02508"></a>02508                                 <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, x, y, color);
<a name="l02509"></a>02509                                 <span class="keywordflow">if</span> (d &gt; 0 || (d == 0 &amp;&amp; sx == 1)) {
<a name="l02510"></a>02510                                         y += sy;
<a name="l02511"></a>02511                                         d -= ax;
<a name="l02512"></a>02512                                 }
<a name="l02513"></a>02513                                 x += sx;
<a name="l02514"></a>02514                                 d += ay;
<a name="l02515"></a>02515                         }
<a name="l02516"></a>02516                 } <span class="keywordflow">else</span> {
<a name="l02517"></a>02517                         <span class="keywordtype">int</span> d = ax - (ay &gt;&gt; 1);
<a name="l02518"></a>02518 
<a name="l02519"></a>02519                         <span class="keywordflow">while</span> (y != y2) {
<a name="l02520"></a>02520                                 <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, x, y, color);
<a name="l02521"></a>02521                                 <span class="keywordflow">if</span> (d &gt; 0 || ((d == 0) &amp;&amp; (sy == 1))) {
<a name="l02522"></a>02522                                         x += sx;
<a name="l02523"></a>02523                                         d -= ay;
<a name="l02524"></a>02524                                 }
<a name="l02525"></a>02525                                 y += sy;
<a name="l02526"></a>02526                                 d += ax;
<a name="l02527"></a>02527                         }
<a name="l02528"></a>02528                 }
<a name="l02529"></a>02529                 <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, x, y, color);
<a name="l02530"></a>02530 
<a name="l02531"></a>02531         }
<a name="l02532"></a>02532 
<a name="l02533"></a>02533         <span class="comment">/* Unlock surface */</span>
<a name="l02534"></a>02534         <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l02535"></a>02535                 SDL_UnlockSurface(dst);
<a name="l02536"></a>02536         }
<a name="l02537"></a>02537 
<a name="l02538"></a>02538         <span class="keywordflow">return</span> (0);
<a name="l02539"></a>02539 }
<a name="l02540"></a>02540 
<a name="l02556"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a5e4bd13b12d34698fbcb2dc9d3a0e9f3">02556</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a760139e11a9ae5defeb755ca0c794f5f" title="Draw line with alpha blending.">lineRGBA</a>(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l02557"></a>02557 {
<a name="l02558"></a>02558         <span class="comment">/*</span>
<a name="l02559"></a>02559 <span class="comment">        * Draw </span>
<a name="l02560"></a>02560 <span class="comment">        */</span>
<a name="l02561"></a>02561         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ad44c550fab3cb736eb049713ede94052" title="Draw line with alpha blending.">lineColor</a>(dst, x1, y1, x2, y2, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a));
<a name="l02562"></a>02562 }
<a name="l02563"></a>02563 
<a name="l02564"></a>02564 <span class="comment">/* AA Line */</span>
<a name="l02565"></a>02565 
<a name="l02566"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#a519bc2d4d753c51da1b956d6c200bff1">02566</a> <span class="preprocessor">#define AAlevels 256</span>
<a name="l02567"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#a2e16571bedf7a97c6fc02d86b48994eb">02567</a> <span class="preprocessor"></span><span class="preprocessor">#define AAbits 8</span>
<a name="l02568"></a>02568 <span class="preprocessor"></span>
<a name="l02589"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#a41cb32b84aee2742fabd5bbaced8e016">02589</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a41cb32b84aee2742fabd5bbaced8e016" title="Internal function to draw anti-aliased line with alpha blending and endpoint control.">_aalineColor</a>(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color, <span class="keywordtype">int</span> draw_endpoint)
<a name="l02590"></a>02590 {
<a name="l02591"></a>02591         Sint32 xx0, yy0, xx1, yy1;
<a name="l02592"></a>02592         <span class="keywordtype">int</span> result;
<a name="l02593"></a>02593         Uint32 intshift, erracc, erradj;
<a name="l02594"></a>02594         Uint32 erracctmp, wgt, wgtcompmask;
<a name="l02595"></a>02595         <span class="keywordtype">int</span> dx, dy, tmp, xdir, y0p1, x0pxdir;
<a name="l02596"></a>02596 
<a name="l02597"></a>02597         <span class="comment">/*</span>
<a name="l02598"></a>02598 <span class="comment">        * Check visibility of clipping rectangle</span>
<a name="l02599"></a>02599 <span class="comment">        */</span>
<a name="l02600"></a>02600         <span class="keywordflow">if</span> ((dst-&gt;clip_rect.w==0) || (dst-&gt;clip_rect.h==0)) {
<a name="l02601"></a>02601                 <span class="keywordflow">return</span>(0);
<a name="l02602"></a>02602         }
<a name="l02603"></a>02603 
<a name="l02604"></a>02604         <span class="comment">/*</span>
<a name="l02605"></a>02605 <span class="comment">        * Clip line and test if we have to draw </span>
<a name="l02606"></a>02606 <span class="comment">        */</span>
<a name="l02607"></a>02607         <span class="keywordflow">if</span> (!(_clipLine(dst, &amp;x1, &amp;y1, &amp;x2, &amp;y2))) {
<a name="l02608"></a>02608                 <span class="keywordflow">return</span> (0);
<a name="l02609"></a>02609         }
<a name="l02610"></a>02610 
<a name="l02611"></a>02611         <span class="comment">/*</span>
<a name="l02612"></a>02612 <span class="comment">        * Keep on working with 32bit numbers </span>
<a name="l02613"></a>02613 <span class="comment">        */</span>
<a name="l02614"></a>02614         xx0 = x1;
<a name="l02615"></a>02615         yy0 = y1;
<a name="l02616"></a>02616         xx1 = x2;
<a name="l02617"></a>02617         yy1 = y2;
<a name="l02618"></a>02618 
<a name="l02619"></a>02619         <span class="comment">/*</span>
<a name="l02620"></a>02620 <span class="comment">        * Reorder points if required </span>
<a name="l02621"></a>02621 <span class="comment">        */</span>
<a name="l02622"></a>02622         <span class="keywordflow">if</span> (yy0 &gt; yy1) {
<a name="l02623"></a>02623                 tmp = yy0;
<a name="l02624"></a>02624                 yy0 = yy1;
<a name="l02625"></a>02625                 yy1 = tmp;
<a name="l02626"></a>02626                 tmp = xx0;
<a name="l02627"></a>02627                 xx0 = xx1;
<a name="l02628"></a>02628                 xx1 = tmp;
<a name="l02629"></a>02629         }
<a name="l02630"></a>02630 
<a name="l02631"></a>02631         <span class="comment">/*</span>
<a name="l02632"></a>02632 <span class="comment">        * Calculate distance </span>
<a name="l02633"></a>02633 <span class="comment">        */</span>
<a name="l02634"></a>02634         dx = xx1 - xx0;
<a name="l02635"></a>02635         dy = yy1 - yy0;
<a name="l02636"></a>02636 
<a name="l02637"></a>02637         <span class="comment">/*</span>
<a name="l02638"></a>02638 <span class="comment">        * Check for special cases </span>
<a name="l02639"></a>02639 <span class="comment">        */</span>
<a name="l02640"></a>02640         <span class="keywordflow">if</span> (dx == 0) {
<a name="l02641"></a>02641                 <span class="comment">/*</span>
<a name="l02642"></a>02642 <span class="comment">                * Vertical line </span>
<a name="l02643"></a>02643 <span class="comment">                */</span>
<a name="l02644"></a>02644                 <span class="keywordflow">if</span> (draw_endpoint)
<a name="l02645"></a>02645                 {
<a name="l02646"></a>02646                         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a9b45060155a19fee24f998d7790f1d67" title="Draw vertical line with blending.">vlineColor</a>(dst, x1, y1, y2, color));
<a name="l02647"></a>02647                 } <span class="keywordflow">else</span> {
<a name="l02648"></a>02648                         <span class="keywordflow">if</span> (dy&gt;0) {
<a name="l02649"></a>02649                                 <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a9b45060155a19fee24f998d7790f1d67" title="Draw vertical line with blending.">vlineColor</a>(dst, x1, yy0, yy0+dy, color));
<a name="l02650"></a>02650                         } <span class="keywordflow">else</span> {
<a name="l02651"></a>02651                                 <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ae6f8690e5c5a85d3263c8e16727b34ef" title="Pixel draw with blending enabled if a&lt;255.">pixelColor</a>(dst, x1, y1, color));
<a name="l02652"></a>02652                         }
<a name="l02653"></a>02653                 }
<a name="l02654"></a>02654         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (dy == 0) {
<a name="l02655"></a>02655                 <span class="comment">/*</span>
<a name="l02656"></a>02656 <span class="comment">                * Horizontal line </span>
<a name="l02657"></a>02657 <span class="comment">                */</span>
<a name="l02658"></a>02658                 <span class="keywordflow">if</span> (draw_endpoint)
<a name="l02659"></a>02659                 {
<a name="l02660"></a>02660                         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, x1, x2, y1, color));
<a name="l02661"></a>02661                 } <span class="keywordflow">else</span> {
<a name="l02662"></a>02662                         <span class="keywordflow">if</span> (dx!=0) {
<a name="l02663"></a>02663                                 <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, xx0, xx0+dx, y1, color));
<a name="l02664"></a>02664                         } <span class="keywordflow">else</span> {
<a name="l02665"></a>02665                                 <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ae6f8690e5c5a85d3263c8e16727b34ef" title="Pixel draw with blending enabled if a&lt;255.">pixelColor</a>(dst, x1, y1, color));
<a name="l02666"></a>02666                         }
<a name="l02667"></a>02667                 }
<a name="l02668"></a>02668         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((dx == dy) &amp;&amp; (draw_endpoint)) {
<a name="l02669"></a>02669                 <span class="comment">/*</span>
<a name="l02670"></a>02670 <span class="comment">                * Diagonal line (with endpoint)</span>
<a name="l02671"></a>02671 <span class="comment">                */</span>
<a name="l02672"></a>02672                 <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ad44c550fab3cb736eb049713ede94052" title="Draw line with alpha blending.">lineColor</a>(dst, x1, y1, x2, y2, color));
<a name="l02673"></a>02673         }
<a name="l02674"></a>02674 
<a name="l02675"></a>02675         <span class="comment">/*</span>
<a name="l02676"></a>02676 <span class="comment">        * Adjust for negative dx and set xdir </span>
<a name="l02677"></a>02677 <span class="comment">        */</span>
<a name="l02678"></a>02678         <span class="keywordflow">if</span> (dx &gt;= 0) {
<a name="l02679"></a>02679                 xdir = 1;
<a name="l02680"></a>02680         } <span class="keywordflow">else</span> {
<a name="l02681"></a>02681                 xdir = -1;
<a name="l02682"></a>02682                 dx = (-dx);
<a name="l02683"></a>02683         }
<a name="l02684"></a>02684 
<a name="l02685"></a>02685         <span class="comment">/*</span>
<a name="l02686"></a>02686 <span class="comment">        * Line is not horizontal, vertical or diagonal (with endpoint)</span>
<a name="l02687"></a>02687 <span class="comment">        */</span>
<a name="l02688"></a>02688         result = 0;
<a name="l02689"></a>02689 
<a name="l02690"></a>02690         <span class="comment">/*</span>
<a name="l02691"></a>02691 <span class="comment">        * Zero accumulator </span>
<a name="l02692"></a>02692 <span class="comment">        */</span>
<a name="l02693"></a>02693         erracc = 0;
<a name="l02694"></a>02694 
<a name="l02695"></a>02695         <span class="comment">/*</span>
<a name="l02696"></a>02696 <span class="comment">        * # of bits by which to shift erracc to get intensity level </span>
<a name="l02697"></a>02697 <span class="comment">        */</span>
<a name="l02698"></a>02698         intshift = 32 - <a class="code" href="_s_d_l__gfx_primitives_8c.html#a2e16571bedf7a97c6fc02d86b48994eb">AAbits</a>;
<a name="l02699"></a>02699 
<a name="l02700"></a>02700         <span class="comment">/*</span>
<a name="l02701"></a>02701 <span class="comment">        * Mask used to flip all bits in an intensity weighting </span>
<a name="l02702"></a>02702 <span class="comment">        */</span>
<a name="l02703"></a>02703         wgtcompmask = <a class="code" href="_s_d_l__gfx_primitives_8c.html#a519bc2d4d753c51da1b956d6c200bff1">AAlevels</a> - 1;
<a name="l02704"></a>02704 
<a name="l02705"></a>02705         <span class="comment">/* Lock surface */</span>
<a name="l02706"></a>02706         <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l02707"></a>02707                 <span class="keywordflow">if</span> (SDL_LockSurface(dst) &lt; 0) {
<a name="l02708"></a>02708                         <span class="keywordflow">return</span> (-1);
<a name="l02709"></a>02709                 }
<a name="l02710"></a>02710         }
<a name="l02711"></a>02711 
<a name="l02712"></a>02712         <span class="comment">/*</span>
<a name="l02713"></a>02713 <span class="comment">        * Draw the initial pixel in the foreground color </span>
<a name="l02714"></a>02714 <span class="comment">        */</span>
<a name="l02715"></a>02715         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(dst, x1, y1, color);
<a name="l02716"></a>02716 
<a name="l02717"></a>02717         <span class="comment">/*</span>
<a name="l02718"></a>02718 <span class="comment">        * x-major or y-major? </span>
<a name="l02719"></a>02719 <span class="comment">        */</span>
<a name="l02720"></a>02720         <span class="keywordflow">if</span> (dy &gt; dx) {
<a name="l02721"></a>02721 
<a name="l02722"></a>02722                 <span class="comment">/*</span>
<a name="l02723"></a>02723 <span class="comment">                * y-major.  Calculate 16-bit fixed point fractional part of a pixel that</span>
<a name="l02724"></a>02724 <span class="comment">                * X advances every time Y advances 1 pixel, truncating the result so that</span>
<a name="l02725"></a>02725 <span class="comment">                * we won&#39;t overrun the endpoint along the X axis </span>
<a name="l02726"></a>02726 <span class="comment">                */</span>
<a name="l02727"></a>02727                 <span class="comment">/*</span>
<a name="l02728"></a>02728 <span class="comment">                * Not-so-portable version: erradj = ((Uint64)dx &lt;&lt; 32) / (Uint64)dy; </span>
<a name="l02729"></a>02729 <span class="comment">                */</span>
<a name="l02730"></a>02730                 erradj = ((dx &lt;&lt; 16) / dy) &lt;&lt; 16;
<a name="l02731"></a>02731 
<a name="l02732"></a>02732                 <span class="comment">/*</span>
<a name="l02733"></a>02733 <span class="comment">                * draw all pixels other than the first and last </span>
<a name="l02734"></a>02734 <span class="comment">                */</span>
<a name="l02735"></a>02735                 x0pxdir = xx0 + xdir;
<a name="l02736"></a>02736                 <span class="keywordflow">while</span> (--dy) {
<a name="l02737"></a>02737                         erracctmp = erracc;
<a name="l02738"></a>02738                         erracc += erradj;
<a name="l02739"></a>02739                         <span class="keywordflow">if</span> (erracc &lt;= erracctmp) {
<a name="l02740"></a>02740                                 <span class="comment">/*</span>
<a name="l02741"></a>02741 <span class="comment">                                * rollover in error accumulator, x coord advances </span>
<a name="l02742"></a>02742 <span class="comment">                                */</span>
<a name="l02743"></a>02743                                 xx0 = x0pxdir;
<a name="l02744"></a>02744                                 x0pxdir += xdir;
<a name="l02745"></a>02745                         }
<a name="l02746"></a>02746                         yy0++;          <span class="comment">/* y-major so always advance Y */</span>
<a name="l02747"></a>02747 
<a name="l02748"></a>02748                         <span class="comment">/*</span>
<a name="l02749"></a>02749 <span class="comment">                        * the AAbits most significant bits of erracc give us the intensity</span>
<a name="l02750"></a>02750 <span class="comment">                        * weighting for this pixel, and the complement of the weighting for</span>
<a name="l02751"></a>02751 <span class="comment">                        * the paired pixel. </span>
<a name="l02752"></a>02752 <span class="comment">                        */</span>
<a name="l02753"></a>02753                         wgt = (erracc &gt;&gt; intshift) &amp; 255;
<a name="l02754"></a>02754                         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a93c580afe80682f06ef4f1655180aff1" title="Pixel draw with blending enabled and using alpha weight on color - no locking.">pixelColorWeightNolock</a> (dst, xx0, yy0, color, 255 - wgt);
<a name="l02755"></a>02755                         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a93c580afe80682f06ef4f1655180aff1" title="Pixel draw with blending enabled and using alpha weight on color - no locking.">pixelColorWeightNolock</a> (dst, x0pxdir, yy0, color, wgt);
<a name="l02756"></a>02756                 }
<a name="l02757"></a>02757 
<a name="l02758"></a>02758         } <span class="keywordflow">else</span> {
<a name="l02759"></a>02759 
<a name="l02760"></a>02760                 <span class="comment">/*</span>
<a name="l02761"></a>02761 <span class="comment">                * x-major line.  Calculate 16-bit fixed-point fractional part of a pixel</span>
<a name="l02762"></a>02762 <span class="comment">                * that Y advances each time X advances 1 pixel, truncating the result so</span>
<a name="l02763"></a>02763 <span class="comment">                * that we won&#39;t overrun the endpoint along the X axis. </span>
<a name="l02764"></a>02764 <span class="comment">                */</span>
<a name="l02765"></a>02765                 <span class="comment">/*</span>
<a name="l02766"></a>02766 <span class="comment">                * Not-so-portable version: erradj = ((Uint64)dy &lt;&lt; 32) / (Uint64)dx; </span>
<a name="l02767"></a>02767 <span class="comment">                */</span>
<a name="l02768"></a>02768                 erradj = ((dy &lt;&lt; 16) / dx) &lt;&lt; 16;
<a name="l02769"></a>02769 
<a name="l02770"></a>02770                 <span class="comment">/*</span>
<a name="l02771"></a>02771 <span class="comment">                * draw all pixels other than the first and last </span>
<a name="l02772"></a>02772 <span class="comment">                */</span>
<a name="l02773"></a>02773                 y0p1 = yy0 + 1;
<a name="l02774"></a>02774                 <span class="keywordflow">while</span> (--dx) {
<a name="l02775"></a>02775 
<a name="l02776"></a>02776                         erracctmp = erracc;
<a name="l02777"></a>02777                         erracc += erradj;
<a name="l02778"></a>02778                         <span class="keywordflow">if</span> (erracc &lt;= erracctmp) {
<a name="l02779"></a>02779                                 <span class="comment">/*</span>
<a name="l02780"></a>02780 <span class="comment">                                * Accumulator turned over, advance y </span>
<a name="l02781"></a>02781 <span class="comment">                                */</span>
<a name="l02782"></a>02782                                 yy0 = y0p1;
<a name="l02783"></a>02783                                 y0p1++;
<a name="l02784"></a>02784                         }
<a name="l02785"></a>02785                         xx0 += xdir;    <span class="comment">/* x-major so always advance X */</span>
<a name="l02786"></a>02786                         <span class="comment">/*</span>
<a name="l02787"></a>02787 <span class="comment">                        * the AAbits most significant bits of erracc give us the intensity</span>
<a name="l02788"></a>02788 <span class="comment">                        * weighting for this pixel, and the complement of the weighting for</span>
<a name="l02789"></a>02789 <span class="comment">                        * the paired pixel. </span>
<a name="l02790"></a>02790 <span class="comment">                        */</span>
<a name="l02791"></a>02791                         wgt = (erracc &gt;&gt; intshift) &amp; 255;
<a name="l02792"></a>02792                         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a93c580afe80682f06ef4f1655180aff1" title="Pixel draw with blending enabled and using alpha weight on color - no locking.">pixelColorWeightNolock</a> (dst, xx0, yy0, color, 255 - wgt);
<a name="l02793"></a>02793                         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a93c580afe80682f06ef4f1655180aff1" title="Pixel draw with blending enabled and using alpha weight on color - no locking.">pixelColorWeightNolock</a> (dst, xx0, y0p1, color, wgt);
<a name="l02794"></a>02794                 }
<a name="l02795"></a>02795         }
<a name="l02796"></a>02796 
<a name="l02797"></a>02797         <span class="comment">/*</span>
<a name="l02798"></a>02798 <span class="comment">        * Do we have to draw the endpoint </span>
<a name="l02799"></a>02799 <span class="comment">        */</span>
<a name="l02800"></a>02800         <span class="keywordflow">if</span> (draw_endpoint) {
<a name="l02801"></a>02801                 <span class="comment">/*</span>
<a name="l02802"></a>02802 <span class="comment">                * Draw final pixel, always exactly intersected by the line and doesn&#39;t</span>
<a name="l02803"></a>02803 <span class="comment">                * need to be weighted. </span>
<a name="l02804"></a>02804 <span class="comment">                */</span>
<a name="l02805"></a>02805                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, x2, y2, color);
<a name="l02806"></a>02806         }
<a name="l02807"></a>02807 
<a name="l02808"></a>02808         <span class="comment">/* Unlock surface */</span>
<a name="l02809"></a>02809         <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l02810"></a>02810                 SDL_UnlockSurface(dst);
<a name="l02811"></a>02811         }
<a name="l02812"></a>02812 
<a name="l02813"></a>02813         <span class="keywordflow">return</span> (result);
<a name="l02814"></a>02814 }
<a name="l02815"></a>02815 
<a name="l02828"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a4711ada424cb411e328fcedbf28ca5bd">02828</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a25c56f2def855db01dcf7ff7f7356182" title="Ddraw anti-aliased line with alpha blending.">aalineColor</a>(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color)
<a name="l02829"></a>02829 {
<a name="l02830"></a>02830         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a41cb32b84aee2742fabd5bbaced8e016" title="Internal function to draw anti-aliased line with alpha blending and endpoint control.">_aalineColor</a>(dst, x1, y1, x2, y2, color, 1));
<a name="l02831"></a>02831 }
<a name="l02832"></a>02832 
<a name="l02848"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#aaf65728167a6aa7b37010560507fb4a2">02848</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a716b29af8cfc638fad0cfa0f1af15f23" title="Draw anti-aliased line with alpha blending.">aalineRGBA</a>(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l02849"></a>02849 {
<a name="l02850"></a>02850         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a41cb32b84aee2742fabd5bbaced8e016" title="Internal function to draw anti-aliased line with alpha blending and endpoint control.">_aalineColor</a>
<a name="l02851"></a>02851                 (dst, x1, y1, x2, y2, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a, 1));
<a name="l02852"></a>02852 }
<a name="l02853"></a>02853 
<a name="l02854"></a>02854 
<a name="l02855"></a>02855 <span class="comment">/* ----- Circle */</span>
<a name="l02856"></a>02856 
<a name="l02872"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a58d231ecaf113f53c2a28435e0632624">02872</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#aa99bd361cc947b448142720f2ca3320e" title="Draw circle with blending.">circleColor</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad, Uint32 color)
<a name="l02873"></a>02873 {
<a name="l02874"></a>02874         Sint16 left, right, top, bottom;
<a name="l02875"></a>02875         <span class="keywordtype">int</span> result;
<a name="l02876"></a>02876         Sint16 x1, y1, x2, y2;
<a name="l02877"></a>02877         Sint16 cx = 0;
<a name="l02878"></a>02878         Sint16 cy = rad;
<a name="l02879"></a>02879         Sint16 df = 1 - rad;
<a name="l02880"></a>02880         Sint16 d_e = 3;
<a name="l02881"></a>02881         Sint16 d_se = -2 * rad + 5;
<a name="l02882"></a>02882         Sint16 xpcx, xmcx, xpcy, xmcy;
<a name="l02883"></a>02883         Sint16 ypcy, ymcy, ypcx, ymcx;
<a name="l02884"></a>02884         Uint8 *colorptr;
<a name="l02885"></a>02885 
<a name="l02886"></a>02886         <span class="comment">/*</span>
<a name="l02887"></a>02887 <span class="comment">        * Check visibility of clipping rectangle</span>
<a name="l02888"></a>02888 <span class="comment">        */</span>
<a name="l02889"></a>02889         <span class="keywordflow">if</span> ((dst-&gt;clip_rect.w==0) || (dst-&gt;clip_rect.h==0)) {
<a name="l02890"></a>02890                 <span class="keywordflow">return</span>(0);
<a name="l02891"></a>02891         }
<a name="l02892"></a>02892 
<a name="l02893"></a>02893         <span class="comment">/*</span>
<a name="l02894"></a>02894 <span class="comment">        * Sanity check radius </span>
<a name="l02895"></a>02895 <span class="comment">        */</span>
<a name="l02896"></a>02896         <span class="keywordflow">if</span> (rad &lt; 0) {
<a name="l02897"></a>02897                 <span class="keywordflow">return</span> (-1);
<a name="l02898"></a>02898         }
<a name="l02899"></a>02899 
<a name="l02900"></a>02900         <span class="comment">/*</span>
<a name="l02901"></a>02901 <span class="comment">        * Special case for rad=0 - draw a point </span>
<a name="l02902"></a>02902 <span class="comment">        */</span>
<a name="l02903"></a>02903         <span class="keywordflow">if</span> (rad == 0) {
<a name="l02904"></a>02904                 <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ae6f8690e5c5a85d3263c8e16727b34ef" title="Pixel draw with blending enabled if a&lt;255.">pixelColor</a>(dst, x, y, color));
<a name="l02905"></a>02905         }
<a name="l02906"></a>02906 
<a name="l02907"></a>02907         <span class="comment">/*</span>
<a name="l02908"></a>02908 <span class="comment">        * Get circle and clipping boundary and </span>
<a name="l02909"></a>02909 <span class="comment">        * test if bounding box of circle is visible </span>
<a name="l02910"></a>02910 <span class="comment">        */</span>
<a name="l02911"></a>02911         x2 = x + rad;
<a name="l02912"></a>02912         left = dst-&gt;clip_rect.x;
<a name="l02913"></a>02913         <span class="keywordflow">if</span> (x2&lt;left) {
<a name="l02914"></a>02914                 <span class="keywordflow">return</span>(0);
<a name="l02915"></a>02915         } 
<a name="l02916"></a>02916         x1 = x - rad;
<a name="l02917"></a>02917         right = dst-&gt;clip_rect.x + dst-&gt;clip_rect.w - 1;
<a name="l02918"></a>02918         <span class="keywordflow">if</span> (x1&gt;right) {
<a name="l02919"></a>02919                 <span class="keywordflow">return</span>(0);
<a name="l02920"></a>02920         } 
<a name="l02921"></a>02921         y2 = y + rad;
<a name="l02922"></a>02922         top = dst-&gt;clip_rect.y;
<a name="l02923"></a>02923         <span class="keywordflow">if</span> (y2&lt;top) {
<a name="l02924"></a>02924                 <span class="keywordflow">return</span>(0);
<a name="l02925"></a>02925         } 
<a name="l02926"></a>02926         y1 = y - rad;
<a name="l02927"></a>02927         bottom = dst-&gt;clip_rect.y + dst-&gt;clip_rect.h - 1;
<a name="l02928"></a>02928         <span class="keywordflow">if</span> (y1&gt;bottom) {
<a name="l02929"></a>02929                 <span class="keywordflow">return</span>(0);
<a name="l02930"></a>02930         } 
<a name="l02931"></a>02931 
<a name="l02932"></a>02932         <span class="comment">/*</span>
<a name="l02933"></a>02933 <span class="comment">        * Draw circle </span>
<a name="l02934"></a>02934 <span class="comment">        */</span>
<a name="l02935"></a>02935         result = 0;
<a name="l02936"></a>02936 
<a name="l02937"></a>02937         <span class="comment">/* Lock surface */</span>
<a name="l02938"></a>02938         <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l02939"></a>02939                 <span class="keywordflow">if</span> (SDL_LockSurface(dst) &lt; 0) {
<a name="l02940"></a>02940                         <span class="keywordflow">return</span> (-1);
<a name="l02941"></a>02941                 }
<a name="l02942"></a>02942         }
<a name="l02943"></a>02943 
<a name="l02944"></a>02944         <span class="comment">/*</span>
<a name="l02945"></a>02945 <span class="comment">        * Alpha Check </span>
<a name="l02946"></a>02946 <span class="comment">        */</span>
<a name="l02947"></a>02947         <span class="keywordflow">if</span> ((color &amp; 255) == 255) {
<a name="l02948"></a>02948 
<a name="l02949"></a>02949                 <span class="comment">/*</span>
<a name="l02950"></a>02950 <span class="comment">                * No Alpha - direct memory writes </span>
<a name="l02951"></a>02951 <span class="comment">                */</span>
<a name="l02952"></a>02952 
<a name="l02953"></a>02953                 <span class="comment">/*</span>
<a name="l02954"></a>02954 <span class="comment">                * Setup color </span>
<a name="l02955"></a>02955 <span class="comment">                */</span>
<a name="l02956"></a>02956                 colorptr = (Uint8 *) &amp; color;
<a name="l02957"></a>02957                 <span class="keywordflow">if</span> (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
<a name="l02958"></a>02958                         color = SDL_MapRGBA(dst-&gt;format, colorptr[0], colorptr[1], colorptr[2], colorptr[3]);
<a name="l02959"></a>02959                 } <span class="keywordflow">else</span> {
<a name="l02960"></a>02960                         color = SDL_MapRGBA(dst-&gt;format, colorptr[3], colorptr[2], colorptr[1], colorptr[0]);
<a name="l02961"></a>02961                 }
<a name="l02962"></a>02962 
<a name="l02963"></a>02963                 <span class="comment">/*</span>
<a name="l02964"></a>02964 <span class="comment">                * Draw </span>
<a name="l02965"></a>02965 <span class="comment">                */</span>
<a name="l02966"></a>02966                 <span class="keywordflow">do</span> {
<a name="l02967"></a>02967                         ypcy = y + cy;
<a name="l02968"></a>02968                         ymcy = y - cy;
<a name="l02969"></a>02969                         <span class="keywordflow">if</span> (cx &gt; 0) {
<a name="l02970"></a>02970                                 xpcx = x + cx;
<a name="l02971"></a>02971                                 xmcx = x - cx;
<a name="l02972"></a>02972                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xmcx, ypcy, color);
<a name="l02973"></a>02973                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xpcx, ypcy, color);
<a name="l02974"></a>02974                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xmcx, ymcy, color);
<a name="l02975"></a>02975                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xpcx, ymcy, color);
<a name="l02976"></a>02976                         } <span class="keywordflow">else</span> {
<a name="l02977"></a>02977                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, x, ymcy, color);
<a name="l02978"></a>02978                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, x, ypcy, color);
<a name="l02979"></a>02979                         }
<a name="l02980"></a>02980                         xpcy = x + cy;
<a name="l02981"></a>02981                         xmcy = x - cy;
<a name="l02982"></a>02982                         <span class="keywordflow">if</span> ((cx &gt; 0) &amp;&amp; (cx != cy)) {
<a name="l02983"></a>02983                                 ypcx = y + cx;
<a name="l02984"></a>02984                                 ymcx = y - cx;
<a name="l02985"></a>02985                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xmcy, ypcx, color);
<a name="l02986"></a>02986                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xpcy, ypcx, color);
<a name="l02987"></a>02987                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xmcy, ymcx, color);
<a name="l02988"></a>02988                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xpcy, ymcx, color);
<a name="l02989"></a>02989                         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (cx == 0) {
<a name="l02990"></a>02990                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xmcy, y, color);
<a name="l02991"></a>02991                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xpcy, y, color);
<a name="l02992"></a>02992                         }
<a name="l02993"></a>02993                         <span class="comment">/*</span>
<a name="l02994"></a>02994 <span class="comment">                        * Update </span>
<a name="l02995"></a>02995 <span class="comment">                        */</span>
<a name="l02996"></a>02996                         <span class="keywordflow">if</span> (df &lt; 0) {
<a name="l02997"></a>02997                                 df += d_e;
<a name="l02998"></a>02998                                 d_e += 2;
<a name="l02999"></a>02999                                 d_se += 2;
<a name="l03000"></a>03000                         } <span class="keywordflow">else</span> {
<a name="l03001"></a>03001                                 df += d_se;
<a name="l03002"></a>03002                                 d_e += 2;
<a name="l03003"></a>03003                                 d_se += 4;
<a name="l03004"></a>03004                                 cy--;
<a name="l03005"></a>03005                         }
<a name="l03006"></a>03006                         cx++;
<a name="l03007"></a>03007                 } <span class="keywordflow">while</span> (cx &lt;= cy);
<a name="l03008"></a>03008 
<a name="l03009"></a>03009                 <span class="comment">/*</span>
<a name="l03010"></a>03010 <span class="comment">                * Unlock surface </span>
<a name="l03011"></a>03011 <span class="comment">                */</span>
<a name="l03012"></a>03012                 SDL_UnlockSurface(dst);
<a name="l03013"></a>03013 
<a name="l03014"></a>03014         } <span class="keywordflow">else</span> {
<a name="l03015"></a>03015 
<a name="l03016"></a>03016                 <span class="comment">/*</span>
<a name="l03017"></a>03017 <span class="comment">                * Using Alpha - blended pixel blits </span>
<a name="l03018"></a>03018 <span class="comment">                */</span>
<a name="l03019"></a>03019 
<a name="l03020"></a>03020                 <span class="keywordflow">do</span> {
<a name="l03021"></a>03021                         <span class="comment">/*</span>
<a name="l03022"></a>03022 <span class="comment">                        * Draw </span>
<a name="l03023"></a>03023 <span class="comment">                        */</span>
<a name="l03024"></a>03024                         ypcy = y + cy;
<a name="l03025"></a>03025                         ymcy = y - cy;
<a name="l03026"></a>03026                         <span class="keywordflow">if</span> (cx &gt; 0) {
<a name="l03027"></a>03027                                 xpcx = x + cx;
<a name="l03028"></a>03028                                 xmcx = x - cx;
<a name="l03029"></a>03029                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xmcx, ypcy, color);
<a name="l03030"></a>03030                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xpcx, ypcy, color);
<a name="l03031"></a>03031                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xmcx, ymcy, color);
<a name="l03032"></a>03032                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xpcx, ymcy, color);
<a name="l03033"></a>03033                         } <span class="keywordflow">else</span> {
<a name="l03034"></a>03034                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, x, ymcy, color);
<a name="l03035"></a>03035                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, x, ypcy, color);
<a name="l03036"></a>03036                         }
<a name="l03037"></a>03037                         xpcy = x + cy;
<a name="l03038"></a>03038                         xmcy = x - cy;
<a name="l03039"></a>03039                         <span class="keywordflow">if</span> ((cx &gt; 0) &amp;&amp; (cx != cy)) {
<a name="l03040"></a>03040                                 ypcx = y + cx;
<a name="l03041"></a>03041                                 ymcx = y - cx;
<a name="l03042"></a>03042                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xmcy, ypcx, color);
<a name="l03043"></a>03043                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xpcy, ypcx, color);
<a name="l03044"></a>03044                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xmcy, ymcx, color);
<a name="l03045"></a>03045                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xpcy, ymcx, color);
<a name="l03046"></a>03046                         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (cx == 0) {
<a name="l03047"></a>03047                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xmcy, y, color);
<a name="l03048"></a>03048                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xpcy, y, color);
<a name="l03049"></a>03049                         }
<a name="l03050"></a>03050                         <span class="comment">/*</span>
<a name="l03051"></a>03051 <span class="comment">                        * Update </span>
<a name="l03052"></a>03052 <span class="comment">                        */</span>
<a name="l03053"></a>03053                         <span class="keywordflow">if</span> (df &lt; 0) {
<a name="l03054"></a>03054                                 df += d_e;
<a name="l03055"></a>03055                                 d_e += 2;
<a name="l03056"></a>03056                                 d_se += 2;
<a name="l03057"></a>03057                         } <span class="keywordflow">else</span> {
<a name="l03058"></a>03058                                 df += d_se;
<a name="l03059"></a>03059                                 d_e += 2;
<a name="l03060"></a>03060                                 d_se += 4;
<a name="l03061"></a>03061                                 cy--;
<a name="l03062"></a>03062                         }
<a name="l03063"></a>03063                         cx++;
<a name="l03064"></a>03064                 } <span class="keywordflow">while</span> (cx &lt;= cy);
<a name="l03065"></a>03065 
<a name="l03066"></a>03066         }                               <span class="comment">/* Alpha check */</span>
<a name="l03067"></a>03067 
<a name="l03068"></a>03068         <span class="comment">/* Unlock surface */</span>
<a name="l03069"></a>03069         <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l03070"></a>03070                 SDL_UnlockSurface(dst);
<a name="l03071"></a>03071         }
<a name="l03072"></a>03072 
<a name="l03073"></a>03073         <span class="keywordflow">return</span> (result);
<a name="l03074"></a>03074 }
<a name="l03075"></a>03075 
<a name="l03090"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a8e0945b74c02cdb1441e1b2a29d2c87d">03090</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a7fe51d4c9426c8795e58c7ddd313b0a4" title="Draw circle with blending.">circleRGBA</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l03091"></a>03091 {
<a name="l03092"></a>03092         <span class="comment">/*</span>
<a name="l03093"></a>03093 <span class="comment">        * Draw </span>
<a name="l03094"></a>03094 <span class="comment">        */</span>
<a name="l03095"></a>03095         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#aa99bd361cc947b448142720f2ca3320e" title="Draw circle with blending.">circleColor</a>(dst, x, y, rad, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a));
<a name="l03096"></a>03096 }
<a name="l03097"></a>03097 
<a name="l03098"></a>03098 <span class="comment">/* ----- Arc */</span>
<a name="l03099"></a>03099 
<a name="l03117"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a6180558aff14d3c240d9e8bf919869ef">03117</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a461b8ac31e00306aee5f8a4c242671d2" title="Arc with blending.">arcColor</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad, Sint16 start, Sint16 end, Uint32 color)
<a name="l03118"></a>03118 {
<a name="l03119"></a>03119         Sint16 left, right, top, bottom;
<a name="l03120"></a>03120         <span class="keywordtype">int</span> result;
<a name="l03121"></a>03121         Sint16 x1, y1, x2, y2;
<a name="l03122"></a>03122         Sint16 cx = 0;
<a name="l03123"></a>03123         Sint16 cy = rad;
<a name="l03124"></a>03124         Sint16 df = 1 - rad;
<a name="l03125"></a>03125         Sint16 d_e = 3;
<a name="l03126"></a>03126         Sint16 d_se = -2 * rad + 5;
<a name="l03127"></a>03127         Sint16 xpcx, xmcx, xpcy, xmcy;
<a name="l03128"></a>03128         Sint16 ypcy, ymcy, ypcx, ymcx;
<a name="l03129"></a>03129         Uint8 *colorptr;
<a name="l03130"></a>03130         Uint8 drawoct;
<a name="l03131"></a>03131         <span class="keywordtype">int</span> startoct, endoct, oct, stopval_start = 0, stopval_end = 0;
<a name="l03132"></a>03132         <span class="keywordtype">double</span> dstart, dend, temp = 0.;
<a name="l03133"></a>03133 
<a name="l03134"></a>03134         <span class="comment">/*</span>
<a name="l03135"></a>03135 <span class="comment">        * Check visibility of clipping rectangle</span>
<a name="l03136"></a>03136 <span class="comment">        */</span>
<a name="l03137"></a>03137         <span class="keywordflow">if</span> ((dst-&gt;clip_rect.w==0) || (dst-&gt;clip_rect.h==0)) {
<a name="l03138"></a>03138                 <span class="keywordflow">return</span>(0);
<a name="l03139"></a>03139         }
<a name="l03140"></a>03140 
<a name="l03141"></a>03141         <span class="comment">/*</span>
<a name="l03142"></a>03142 <span class="comment">        * Sanity check radius </span>
<a name="l03143"></a>03143 <span class="comment">        */</span>
<a name="l03144"></a>03144         <span class="keywordflow">if</span> (rad &lt; 0) {
<a name="l03145"></a>03145                 <span class="keywordflow">return</span> (-1);
<a name="l03146"></a>03146         }
<a name="l03147"></a>03147 
<a name="l03148"></a>03148         <span class="comment">/*</span>
<a name="l03149"></a>03149 <span class="comment">        * Special case for rad=0 - draw a point </span>
<a name="l03150"></a>03150 <span class="comment">        */</span>
<a name="l03151"></a>03151         <span class="keywordflow">if</span> (rad == 0) {
<a name="l03152"></a>03152                 <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ae6f8690e5c5a85d3263c8e16727b34ef" title="Pixel draw with blending enabled if a&lt;255.">pixelColor</a>(dst, x, y, color));
<a name="l03153"></a>03153         }
<a name="l03154"></a>03154 
<a name="l03155"></a>03155         <span class="comment">/*</span>
<a name="l03156"></a>03156 <span class="comment">        * Get arc&#39;s circle and clipping boundary and </span>
<a name="l03157"></a>03157 <span class="comment">        * test if bounding box of circle is visible </span>
<a name="l03158"></a>03158 <span class="comment">        */</span>
<a name="l03159"></a>03159         x2 = x + rad;
<a name="l03160"></a>03160         left = dst-&gt;clip_rect.x;
<a name="l03161"></a>03161         <span class="keywordflow">if</span> (x2&lt;left) {
<a name="l03162"></a>03162                 <span class="keywordflow">return</span>(0);
<a name="l03163"></a>03163         } 
<a name="l03164"></a>03164         x1 = x - rad;
<a name="l03165"></a>03165         right = dst-&gt;clip_rect.x + dst-&gt;clip_rect.w - 1;
<a name="l03166"></a>03166         <span class="keywordflow">if</span> (x1&gt;right) {
<a name="l03167"></a>03167                 <span class="keywordflow">return</span>(0);
<a name="l03168"></a>03168         } 
<a name="l03169"></a>03169         y2 = y + rad;
<a name="l03170"></a>03170         top = dst-&gt;clip_rect.y;
<a name="l03171"></a>03171         <span class="keywordflow">if</span> (y2&lt;top) {
<a name="l03172"></a>03172                 <span class="keywordflow">return</span>(0);
<a name="l03173"></a>03173         } 
<a name="l03174"></a>03174         y1 = y - rad;
<a name="l03175"></a>03175         bottom = dst-&gt;clip_rect.y + dst-&gt;clip_rect.h - 1;
<a name="l03176"></a>03176         <span class="keywordflow">if</span> (y1&gt;bottom) {
<a name="l03177"></a>03177                 <span class="keywordflow">return</span>(0);
<a name="l03178"></a>03178         }  
<a name="l03179"></a>03179 
<a name="l03180"></a>03180         <span class="comment">// Octant labelling</span>
<a name="l03181"></a>03181         <span class="comment">//      </span>
<a name="l03182"></a>03182         <span class="comment">//  \ 5 | 6 /</span>
<a name="l03183"></a>03183         <span class="comment">//   \  |  /</span>
<a name="l03184"></a>03184         <span class="comment">//  4 \ | / 7</span>
<a name="l03185"></a>03185         <span class="comment">//     \|/</span>
<a name="l03186"></a>03186         <span class="comment">//------+------ +x</span>
<a name="l03187"></a>03187         <span class="comment">//     /|\</span>
<a name="l03188"></a>03188 <span class="comment">        //  3 / | \ 0</span>
<a name="l03189"></a>03189         <span class="comment">//   /  |  \</span>
<a name="l03190"></a>03190 <span class="comment">        //  / 2 | 1 \</span>
<a name="l03191"></a>03191 <span class="comment">        //      +y</span>
<a name="l03192"></a>03192 
<a name="l03193"></a>03193         <span class="comment">// Initially reset bitmask to 0x00000000</span>
<a name="l03194"></a>03194         <span class="comment">// the set whether or not to keep drawing a given octant.</span>
<a name="l03195"></a>03195         <span class="comment">// For example: 0x00111100 means we&#39;re drawing in octants 2-5</span>
<a name="l03196"></a>03196         drawoct = 0; 
<a name="l03197"></a>03197 
<a name="l03198"></a>03198         <span class="comment">/*</span>
<a name="l03199"></a>03199 <span class="comment">        * Fixup angles</span>
<a name="l03200"></a>03200 <span class="comment">        */</span>
<a name="l03201"></a>03201         start %= 360;
<a name="l03202"></a>03202         end %= 360;
<a name="l03203"></a>03203         <span class="comment">// 0 &lt;= start &amp; end &lt; 360; note that sometimes start &gt; end - if so, arc goes back through 0.</span>
<a name="l03204"></a>03204         <span class="keywordflow">while</span> (start &lt; 0) start += 360;
<a name="l03205"></a>03205         <span class="keywordflow">while</span> (end &lt; 0) end += 360;
<a name="l03206"></a>03206         start %= 360;
<a name="l03207"></a>03207         end %= 360;
<a name="l03208"></a>03208 
<a name="l03209"></a>03209         <span class="comment">// now, we find which octants we&#39;re drawing in.</span>
<a name="l03210"></a>03210         startoct = start / 45;
<a name="l03211"></a>03211         endoct = end / 45;
<a name="l03212"></a>03212         oct = startoct - 1; <span class="comment">// we increment as first step in loop</span>
<a name="l03213"></a>03213 
<a name="l03214"></a>03214         <span class="comment">// stopval_start, stopval_end; </span>
<a name="l03215"></a>03215         <span class="comment">// what values of cx to stop at.</span>
<a name="l03216"></a>03216         <span class="keywordflow">do</span> {
<a name="l03217"></a>03217                 oct = (oct + 1) % 8;
<a name="l03218"></a>03218 
<a name="l03219"></a>03219                 <span class="keywordflow">if</span> (oct == startoct) {
<a name="l03220"></a>03220                         <span class="comment">// need to compute stopval_start for this octant.  Look at picture above if this is unclear</span>
<a name="l03221"></a>03221                         dstart = (double)start;
<a name="l03222"></a>03222                         <span class="keywordflow">switch</span> (oct) 
<a name="l03223"></a>03223                         {
<a name="l03224"></a>03224                         <span class="keywordflow">case</span> 0:
<a name="l03225"></a>03225                         <span class="keywordflow">case</span> 3:
<a name="l03226"></a>03226                                 temp = sin(dstart * <a class="code" href="_s_d_l__gfx_primitives_8h.html#ae71449b1cc6e6250b91f539153a7a0d3">M_PI</a> / 180.);
<a name="l03227"></a>03227                                 <span class="keywordflow">break</span>;
<a name="l03228"></a>03228                         <span class="keywordflow">case</span> 1:
<a name="l03229"></a>03229                         <span class="keywordflow">case</span> 6:
<a name="l03230"></a>03230                                 temp = cos(dstart * <a class="code" href="_s_d_l__gfx_primitives_8h.html#ae71449b1cc6e6250b91f539153a7a0d3">M_PI</a> / 180.);
<a name="l03231"></a>03231                                 <span class="keywordflow">break</span>;
<a name="l03232"></a>03232                         <span class="keywordflow">case</span> 2:
<a name="l03233"></a>03233                         <span class="keywordflow">case</span> 5:
<a name="l03234"></a>03234                                 temp = -cos(dstart * <a class="code" href="_s_d_l__gfx_primitives_8h.html#ae71449b1cc6e6250b91f539153a7a0d3">M_PI</a> / 180.);
<a name="l03235"></a>03235                                 <span class="keywordflow">break</span>;
<a name="l03236"></a>03236                         <span class="keywordflow">case</span> 4:
<a name="l03237"></a>03237                         <span class="keywordflow">case</span> 7:
<a name="l03238"></a>03238                                 temp = -sin(dstart * <a class="code" href="_s_d_l__gfx_primitives_8h.html#ae71449b1cc6e6250b91f539153a7a0d3">M_PI</a> / 180.);
<a name="l03239"></a>03239                                 <span class="keywordflow">break</span>;
<a name="l03240"></a>03240                         }
<a name="l03241"></a>03241                         temp *= rad;
<a name="l03242"></a>03242                         stopval_start = (int)temp; <span class="comment">// always round down.</span>
<a name="l03243"></a>03243                         <span class="comment">// This isn&#39;t arbitrary, but requires graph paper to explain well.</span>
<a name="l03244"></a>03244                         <span class="comment">// The basic idea is that we&#39;re always changing drawoct after we draw, so we</span>
<a name="l03245"></a>03245                         <span class="comment">// stop immediately after we render the last sensible pixel at x = ((int)temp).</span>
<a name="l03246"></a>03246 
<a name="l03247"></a>03247                         <span class="comment">// and whether to draw in this octant initially</span>
<a name="l03248"></a>03248                         <span class="keywordflow">if</span> (oct % 2) drawoct |= (1 &lt;&lt; oct); <span class="comment">// this is basically like saying drawoct[oct] = true, if drawoct were a bool array</span>
<a name="l03249"></a>03249                         <span class="keywordflow">else</span>             drawoct &amp;= 255 - (1 &lt;&lt; oct); <span class="comment">// this is basically like saying drawoct[oct] = false</span>
<a name="l03250"></a>03250                 }
<a name="l03251"></a>03251                 <span class="keywordflow">if</span> (oct == endoct) {
<a name="l03252"></a>03252                         <span class="comment">// need to compute stopval_end for this octant</span>
<a name="l03253"></a>03253                         dend = (double)end;
<a name="l03254"></a>03254                         <span class="keywordflow">switch</span> (oct)
<a name="l03255"></a>03255                         {
<a name="l03256"></a>03256                         <span class="keywordflow">case</span> 0:
<a name="l03257"></a>03257                         <span class="keywordflow">case</span> 3:
<a name="l03258"></a>03258                                 temp = sin(dend * <a class="code" href="_s_d_l__gfx_primitives_8h.html#ae71449b1cc6e6250b91f539153a7a0d3">M_PI</a> / 180);
<a name="l03259"></a>03259                                 <span class="keywordflow">break</span>;
<a name="l03260"></a>03260                         <span class="keywordflow">case</span> 1:
<a name="l03261"></a>03261                         <span class="keywordflow">case</span> 6:
<a name="l03262"></a>03262                                 temp = cos(dend * <a class="code" href="_s_d_l__gfx_primitives_8h.html#ae71449b1cc6e6250b91f539153a7a0d3">M_PI</a> / 180);
<a name="l03263"></a>03263                                 <span class="keywordflow">break</span>;
<a name="l03264"></a>03264                         <span class="keywordflow">case</span> 2:
<a name="l03265"></a>03265                         <span class="keywordflow">case</span> 5:
<a name="l03266"></a>03266                                 temp = -cos(dend * <a class="code" href="_s_d_l__gfx_primitives_8h.html#ae71449b1cc6e6250b91f539153a7a0d3">M_PI</a> / 180);
<a name="l03267"></a>03267                                 <span class="keywordflow">break</span>;
<a name="l03268"></a>03268                         <span class="keywordflow">case</span> 4:
<a name="l03269"></a>03269                         <span class="keywordflow">case</span> 7:
<a name="l03270"></a>03270                                 temp = -sin(dend * <a class="code" href="_s_d_l__gfx_primitives_8h.html#ae71449b1cc6e6250b91f539153a7a0d3">M_PI</a> / 180);
<a name="l03271"></a>03271                                 <span class="keywordflow">break</span>;
<a name="l03272"></a>03272                         }
<a name="l03273"></a>03273                         temp *= rad;
<a name="l03274"></a>03274                         stopval_end = (int)temp;
<a name="l03275"></a>03275 
<a name="l03276"></a>03276                         <span class="comment">// and whether to draw in this octant initially</span>
<a name="l03277"></a>03277                         <span class="keywordflow">if</span> (startoct == endoct) {
<a name="l03278"></a>03278                                 <span class="comment">// note:      we start drawing, stop, then start again in this case</span>
<a name="l03279"></a>03279                                 <span class="comment">// otherwise: we only draw in this octant, so initialize it to false, it will get set back to true</span>
<a name="l03280"></a>03280                                 <span class="keywordflow">if</span> (start &gt; end) {
<a name="l03281"></a>03281                                         <span class="comment">// unfortunately, if we&#39;re in the same octant and need to draw over the whole circle, </span>
<a name="l03282"></a>03282                                         <span class="comment">// we need to set the rest to true, because the while loop will end at the bottom.</span>
<a name="l03283"></a>03283                                         drawoct = 255;
<a name="l03284"></a>03284                                 } <span class="keywordflow">else</span> {
<a name="l03285"></a>03285                                         drawoct &amp;= 255 - (1 &lt;&lt; oct);
<a name="l03286"></a>03286                                 }
<a name="l03287"></a>03287                         } 
<a name="l03288"></a>03288                         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (oct % 2) drawoct &amp;= 255 - (1 &lt;&lt; oct);
<a name="l03289"></a>03289                         <span class="keywordflow">else</span>                      drawoct |= (1 &lt;&lt; oct);
<a name="l03290"></a>03290                 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (oct != startoct) { <span class="comment">// already verified that it&#39;s != endoct</span>
<a name="l03291"></a>03291                         drawoct |= (1 &lt;&lt; oct); <span class="comment">// draw this entire segment</span>
<a name="l03292"></a>03292                 }
<a name="l03293"></a>03293         } <span class="keywordflow">while</span> (oct != endoct);
<a name="l03294"></a>03294 
<a name="l03295"></a>03295         <span class="comment">// so now we have what octants to draw and when to draw them.  all that&#39;s left is the actual raster code.</span>
<a name="l03296"></a>03296 
<a name="l03297"></a>03297         <span class="comment">/* Lock surface */</span>
<a name="l03298"></a>03298         <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l03299"></a>03299                 <span class="keywordflow">if</span> (SDL_LockSurface(dst) &lt; 0) {
<a name="l03300"></a>03300                         <span class="keywordflow">return</span> (-1);
<a name="l03301"></a>03301                 }
<a name="l03302"></a>03302         }
<a name="l03303"></a>03303 
<a name="l03304"></a>03304         <span class="comment">/*</span>
<a name="l03305"></a>03305 <span class="comment">        * Draw arc </span>
<a name="l03306"></a>03306 <span class="comment">        */</span>
<a name="l03307"></a>03307         result = 0;
<a name="l03308"></a>03308 
<a name="l03309"></a>03309         <span class="comment">/*</span>
<a name="l03310"></a>03310 <span class="comment">        * Alpha Check </span>
<a name="l03311"></a>03311 <span class="comment">        */</span>
<a name="l03312"></a>03312         <span class="keywordflow">if</span> ((color &amp; 255) == 255) {
<a name="l03313"></a>03313 
<a name="l03314"></a>03314                 <span class="comment">/*</span>
<a name="l03315"></a>03315 <span class="comment">                * No Alpha - direct memory writes </span>
<a name="l03316"></a>03316 <span class="comment">                */</span>
<a name="l03317"></a>03317 
<a name="l03318"></a>03318                 <span class="comment">/*</span>
<a name="l03319"></a>03319 <span class="comment">                * Setup color </span>
<a name="l03320"></a>03320 <span class="comment">                */</span>
<a name="l03321"></a>03321                 colorptr = (Uint8 *) &amp; color;
<a name="l03322"></a>03322                 <span class="keywordflow">if</span> (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
<a name="l03323"></a>03323                         color = SDL_MapRGBA(dst-&gt;format, colorptr[0], colorptr[1], colorptr[2], colorptr[3]);
<a name="l03324"></a>03324                 } <span class="keywordflow">else</span> {
<a name="l03325"></a>03325                         color = SDL_MapRGBA(dst-&gt;format, colorptr[3], colorptr[2], colorptr[1], colorptr[0]);
<a name="l03326"></a>03326                 }
<a name="l03327"></a>03327 
<a name="l03328"></a>03328                 <span class="comment">/*</span>
<a name="l03329"></a>03329 <span class="comment">                * Draw </span>
<a name="l03330"></a>03330 <span class="comment">                */</span>
<a name="l03331"></a>03331                 <span class="keywordflow">do</span> {
<a name="l03332"></a>03332                         ypcy = y + cy;
<a name="l03333"></a>03333                         ymcy = y - cy;
<a name="l03334"></a>03334                         <span class="keywordflow">if</span> (cx &gt; 0) {
<a name="l03335"></a>03335                                 xpcx = x + cx;
<a name="l03336"></a>03336                                 xmcx = x - cx;
<a name="l03337"></a>03337                                 <span class="comment">// always check if we&#39;re drawing a certain octant before adding a pixel to that octant.</span>
<a name="l03338"></a>03338                                 <span class="keywordflow">if</span> (drawoct &amp; 4)  result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xmcx, ypcy, color); <span class="comment">// drawoct &amp; 4 = 22; drawoct[2]</span>
<a name="l03339"></a>03339                                 <span class="keywordflow">if</span> (drawoct &amp; 2)  result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xpcx, ypcy, color);
<a name="l03340"></a>03340                                 <span class="keywordflow">if</span> (drawoct &amp; 32) result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xmcx, ymcy, color);
<a name="l03341"></a>03341                                 <span class="keywordflow">if</span> (drawoct &amp; 64) result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xpcx, ymcy, color);
<a name="l03342"></a>03342                         } <span class="keywordflow">else</span> {
<a name="l03343"></a>03343                                 <span class="keywordflow">if</span> (drawoct &amp; 6)  result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, x, ypcy, color); <span class="comment">// 4 + 2; drawoct[2] || drawoct[1]</span>
<a name="l03344"></a>03344                                 <span class="keywordflow">if</span> (drawoct &amp; 96) result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, x, ymcy, color); <span class="comment">// 32 + 64</span>
<a name="l03345"></a>03345                         }
<a name="l03346"></a>03346 
<a name="l03347"></a>03347                         xpcy = x + cy;
<a name="l03348"></a>03348                         xmcy = x - cy;
<a name="l03349"></a>03349                         <span class="keywordflow">if</span> (cx &gt; 0 &amp;&amp; cx != cy) {
<a name="l03350"></a>03350                                 ypcx = y + cx;
<a name="l03351"></a>03351                                 ymcx = y - cx;
<a name="l03352"></a>03352                                 <span class="keywordflow">if</span> (drawoct &amp; 8)   result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xmcy, ypcx, color);
<a name="l03353"></a>03353                                 <span class="keywordflow">if</span> (drawoct &amp; 1)   result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xpcy, ypcx, color);
<a name="l03354"></a>03354                                 <span class="keywordflow">if</span> (drawoct &amp; 16)  result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xmcy, ymcx, color);
<a name="l03355"></a>03355                                 <span class="keywordflow">if</span> (drawoct &amp; 128) result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xpcy, ymcx, color);
<a name="l03356"></a>03356                         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (cx == 0) {
<a name="l03357"></a>03357                                 <span class="keywordflow">if</span> (drawoct &amp; 24)  result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xmcy, y, color); <span class="comment">// 8 + 16</span>
<a name="l03358"></a>03358                                 <span class="keywordflow">if</span> (drawoct &amp; 129) result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xpcy, y, color); <span class="comment">// 1 + 128</span>
<a name="l03359"></a>03359                         }
<a name="l03360"></a>03360 
<a name="l03361"></a>03361                         <span class="comment">/*</span>
<a name="l03362"></a>03362 <span class="comment">                        * Update whether we&#39;re drawing an octant</span>
<a name="l03363"></a>03363 <span class="comment">                        */</span>
<a name="l03364"></a>03364                         <span class="keywordflow">if</span> (stopval_start == cx) {
<a name="l03365"></a>03365                                 <span class="comment">// works like an on-off switch because start &amp; end may be in the same octant.</span>
<a name="l03366"></a>03366                                 <span class="keywordflow">if</span> (drawoct &amp; (1 &lt;&lt; startoct)) drawoct &amp;= 255 - (1 &lt;&lt; startoct);                
<a name="l03367"></a>03367                                 <span class="keywordflow">else</span> drawoct |= (1 &lt;&lt; startoct);
<a name="l03368"></a>03368                         }
<a name="l03369"></a>03369                         <span class="keywordflow">if</span> (stopval_end == cx) {
<a name="l03370"></a>03370                                 <span class="keywordflow">if</span> (drawoct &amp; (1 &lt;&lt; endoct)) drawoct &amp;= 255 - (1 &lt;&lt; endoct);
<a name="l03371"></a>03371                                 <span class="keywordflow">else</span> drawoct |= (1 &lt;&lt; endoct);
<a name="l03372"></a>03372                         }
<a name="l03373"></a>03373 
<a name="l03374"></a>03374                         <span class="comment">/*</span>
<a name="l03375"></a>03375 <span class="comment">                        * Update pixels</span>
<a name="l03376"></a>03376 <span class="comment">                        */</span>
<a name="l03377"></a>03377                         <span class="keywordflow">if</span> (df &lt; 0) {
<a name="l03378"></a>03378                                 df += d_e;
<a name="l03379"></a>03379                                 d_e += 2;
<a name="l03380"></a>03380                                 d_se += 2;
<a name="l03381"></a>03381                         } <span class="keywordflow">else</span> {
<a name="l03382"></a>03382                                 df += d_se;
<a name="l03383"></a>03383                                 d_e += 2;
<a name="l03384"></a>03384                                 d_se += 4;
<a name="l03385"></a>03385                                 cy--;
<a name="l03386"></a>03386                         }
<a name="l03387"></a>03387                         cx++;
<a name="l03388"></a>03388                 } <span class="keywordflow">while</span> (cx &lt;= cy);
<a name="l03389"></a>03389 
<a name="l03390"></a>03390                 <span class="comment">/*</span>
<a name="l03391"></a>03391 <span class="comment">                * Unlock surface </span>
<a name="l03392"></a>03392 <span class="comment">                */</span>
<a name="l03393"></a>03393                 SDL_UnlockSurface(dst);
<a name="l03394"></a>03394 
<a name="l03395"></a>03395         } <span class="keywordflow">else</span> {
<a name="l03396"></a>03396 
<a name="l03397"></a>03397                 <span class="comment">/*</span>
<a name="l03398"></a>03398 <span class="comment">                * Using Alpha - blended pixel blits </span>
<a name="l03399"></a>03399 <span class="comment">                */</span>
<a name="l03400"></a>03400 
<a name="l03401"></a>03401                 <span class="keywordflow">do</span> {
<a name="l03402"></a>03402                         ypcy = y + cy;
<a name="l03403"></a>03403                         ymcy = y - cy;
<a name="l03404"></a>03404                         <span class="keywordflow">if</span> (cx &gt; 0) {
<a name="l03405"></a>03405                                 xpcx = x + cx;
<a name="l03406"></a>03406                                 xmcx = x - cx;
<a name="l03407"></a>03407 
<a name="l03408"></a>03408                                 <span class="comment">// always check if we&#39;re drawing a certain octant before adding a pixel to that octant.</span>
<a name="l03409"></a>03409                                 <span class="keywordflow">if</span> (drawoct &amp; 4)  result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(dst, xmcx, ypcy, color);
<a name="l03410"></a>03410                                 <span class="keywordflow">if</span> (drawoct &amp; 2)  result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(dst, xpcx, ypcy, color);
<a name="l03411"></a>03411                                 <span class="keywordflow">if</span> (drawoct &amp; 32) result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(dst, xmcx, ymcy, color);
<a name="l03412"></a>03412                                 <span class="keywordflow">if</span> (drawoct &amp; 64) result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(dst, xpcx, ymcy, color);
<a name="l03413"></a>03413                         } <span class="keywordflow">else</span> {
<a name="l03414"></a>03414                                 <span class="keywordflow">if</span> (drawoct &amp; 96) result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(dst, x, ymcy, color);
<a name="l03415"></a>03415                                 <span class="keywordflow">if</span> (drawoct &amp; 6)  result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(dst, x, ypcy, color);
<a name="l03416"></a>03416                         }
<a name="l03417"></a>03417 
<a name="l03418"></a>03418                         xpcy = x + cy;
<a name="l03419"></a>03419                         xmcy = x - cy;
<a name="l03420"></a>03420                         <span class="keywordflow">if</span> (cx &gt; 0 &amp;&amp; cx != cy) {
<a name="l03421"></a>03421                                 ypcx = y + cx;
<a name="l03422"></a>03422                                 ymcx = y - cx;
<a name="l03423"></a>03423                                 <span class="keywordflow">if</span> (drawoct &amp; 8)   result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(dst, xmcy, ypcx, color);
<a name="l03424"></a>03424                                 <span class="keywordflow">if</span> (drawoct &amp; 1)   result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(dst, xpcy, ypcx, color);
<a name="l03425"></a>03425                                 <span class="keywordflow">if</span> (drawoct &amp; 16)  result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(dst, xmcy, ymcx, color);
<a name="l03426"></a>03426                                 <span class="keywordflow">if</span> (drawoct &amp; 128) result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(dst, xpcy, ymcx, color);
<a name="l03427"></a>03427                         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (cx == 0) {
<a name="l03428"></a>03428                                 <span class="keywordflow">if</span> (drawoct &amp; 24)  result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(dst, xmcy, y, color);
<a name="l03429"></a>03429                                 <span class="keywordflow">if</span> (drawoct &amp; 129) result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(dst, xpcy, y, color);
<a name="l03430"></a>03430                         }
<a name="l03431"></a>03431 
<a name="l03432"></a>03432                         <span class="comment">/*</span>
<a name="l03433"></a>03433 <span class="comment">                        * Update whether we&#39;re drawing an octant</span>
<a name="l03434"></a>03434 <span class="comment">                        */</span>
<a name="l03435"></a>03435                         <span class="keywordflow">if</span> (stopval_start == cx) {
<a name="l03436"></a>03436                                 <span class="comment">// works like an on-off switch.  </span>
<a name="l03437"></a>03437                                 <span class="comment">// This is just in case start &amp; end are in the same octant.</span>
<a name="l03438"></a>03438                                 <span class="keywordflow">if</span> (drawoct &amp; (1 &lt;&lt; startoct)) drawoct &amp;= 255 - (1 &lt;&lt; startoct);                
<a name="l03439"></a>03439                                 <span class="keywordflow">else</span>                                               drawoct |= (1 &lt;&lt; startoct);
<a name="l03440"></a>03440                         }
<a name="l03441"></a>03441                         <span class="keywordflow">if</span> (stopval_end == cx) {
<a name="l03442"></a>03442                                 <span class="keywordflow">if</span> (drawoct &amp; (1 &lt;&lt; endoct)) drawoct &amp;= 255 - (1 &lt;&lt; endoct);
<a name="l03443"></a>03443                                 <span class="keywordflow">else</span>                                             drawoct |= (1 &lt;&lt; endoct);
<a name="l03444"></a>03444                         }
<a name="l03445"></a>03445 
<a name="l03446"></a>03446                         <span class="comment">/*</span>
<a name="l03447"></a>03447 <span class="comment">                        * Update pixels</span>
<a name="l03448"></a>03448 <span class="comment">                        */</span>
<a name="l03449"></a>03449                         <span class="keywordflow">if</span> (df &lt; 0) {
<a name="l03450"></a>03450                                 df += d_e;
<a name="l03451"></a>03451                                 d_e += 2;
<a name="l03452"></a>03452                                 d_se += 2;
<a name="l03453"></a>03453                         } <span class="keywordflow">else</span> {
<a name="l03454"></a>03454                                 df += d_se;
<a name="l03455"></a>03455                                 d_e += 2;
<a name="l03456"></a>03456                                 d_se += 4;
<a name="l03457"></a>03457                                 cy--;
<a name="l03458"></a>03458                         }
<a name="l03459"></a>03459                         cx++;
<a name="l03460"></a>03460                 } <span class="keywordflow">while</span> (cx &lt;= cy);
<a name="l03461"></a>03461 
<a name="l03462"></a>03462         }                               <span class="comment">/* Alpha check */</span>
<a name="l03463"></a>03463 
<a name="l03464"></a>03464         <span class="comment">/* Unlock surface */</span>
<a name="l03465"></a>03465         <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l03466"></a>03466                 SDL_UnlockSurface(dst);
<a name="l03467"></a>03467         }
<a name="l03468"></a>03468 
<a name="l03469"></a>03469         <span class="keywordflow">return</span> (result);
<a name="l03470"></a>03470 }
<a name="l03471"></a>03471 
<a name="l03488"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a5d8d25ecb69e9386289125eb21668a2f">03488</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a2aff993d0d8d64564e16145f401d3cf1" title="Arc with blending.">arcRGBA</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad, Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l03489"></a>03489 {
<a name="l03490"></a>03490         <span class="comment">/*</span>
<a name="l03491"></a>03491 <span class="comment">        * Draw </span>
<a name="l03492"></a>03492 <span class="comment">        */</span>
<a name="l03493"></a>03493         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a461b8ac31e00306aee5f8a4c242671d2" title="Arc with blending.">arcColor</a>(dst, x, y, rad, start, end, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a));
<a name="l03494"></a>03494 }
<a name="l03495"></a>03495 
<a name="l03496"></a>03496 <span class="comment">/* ----- AA Circle */</span>
<a name="l03497"></a>03497 
<a name="l03498"></a>03498 
<a name="l03512"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#aee66c744f9fbe58c9f93ad33375373c3">03512</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#aad64361b01181e6aff940add96d23c61" title="Draw anti-aliased circle with blending.">aacircleColor</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad, Uint32 color)
<a name="l03513"></a>03513 {
<a name="l03514"></a>03514         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a1c7d20dcba8e0d7ce483f4c854c438be" title="Draw anti-aliased ellipse with blending.">aaellipseColor</a>(dst, x, y, rad, rad, color));
<a name="l03515"></a>03515 }
<a name="l03516"></a>03516 
<a name="l03531"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a613099498679e6280959cdfdcd59a143">03531</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a332780885aa2cfdc2de34dcff8d67e8b" title="Draw anti-aliased circle with blending.">aacircleRGBA</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l03532"></a>03532 {
<a name="l03533"></a>03533         <span class="comment">/*</span>
<a name="l03534"></a>03534 <span class="comment">        * Draw </span>
<a name="l03535"></a>03535 <span class="comment">        */</span>
<a name="l03536"></a>03536         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a1c7d20dcba8e0d7ce483f4c854c438be" title="Draw anti-aliased ellipse with blending.">aaellipseColor</a>
<a name="l03537"></a>03537                 (dst, x, y, rad, rad, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a));
<a name="l03538"></a>03538 }
<a name="l03539"></a>03539 
<a name="l03540"></a>03540 <span class="comment">/* ----- Filled Circle */</span>
<a name="l03541"></a>03541 
<a name="l03556"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a4f7b717b958ef39bfc8c958476dd0de1">03556</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a39147d1282ec814a1b9e31243aad0359" title="Draw filled circle with blending.">filledCircleColor</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad, Uint32 color)
<a name="l03557"></a>03557 {
<a name="l03558"></a>03558         Sint16 left, right, top, bottom;
<a name="l03559"></a>03559         <span class="keywordtype">int</span> result;
<a name="l03560"></a>03560         Sint16 x1, y1, x2, y2;
<a name="l03561"></a>03561         Sint16 cx = 0;
<a name="l03562"></a>03562         Sint16 cy = rad;
<a name="l03563"></a>03563         Sint16 ocx = (Sint16) 0xffff;
<a name="l03564"></a>03564         Sint16 ocy = (Sint16) 0xffff;
<a name="l03565"></a>03565         Sint16 df = 1 - rad;
<a name="l03566"></a>03566         Sint16 d_e = 3;
<a name="l03567"></a>03567         Sint16 d_se = -2 * rad + 5;
<a name="l03568"></a>03568         Sint16 xpcx, xmcx, xpcy, xmcy;
<a name="l03569"></a>03569         Sint16 ypcy, ymcy, ypcx, ymcx;
<a name="l03570"></a>03570 
<a name="l03571"></a>03571         <span class="comment">/*</span>
<a name="l03572"></a>03572 <span class="comment">        * Check visibility of clipping rectangle</span>
<a name="l03573"></a>03573 <span class="comment">        */</span>
<a name="l03574"></a>03574         <span class="keywordflow">if</span> ((dst-&gt;clip_rect.w==0) || (dst-&gt;clip_rect.h==0)) {
<a name="l03575"></a>03575                 <span class="keywordflow">return</span>(0);
<a name="l03576"></a>03576         }
<a name="l03577"></a>03577 
<a name="l03578"></a>03578         <span class="comment">/*</span>
<a name="l03579"></a>03579 <span class="comment">        * Sanity check radius </span>
<a name="l03580"></a>03580 <span class="comment">        */</span>
<a name="l03581"></a>03581         <span class="keywordflow">if</span> (rad &lt; 0) {
<a name="l03582"></a>03582                 <span class="keywordflow">return</span> (-1);
<a name="l03583"></a>03583         }
<a name="l03584"></a>03584 
<a name="l03585"></a>03585         <span class="comment">/*</span>
<a name="l03586"></a>03586 <span class="comment">        * Special case for rad=0 - draw a point </span>
<a name="l03587"></a>03587 <span class="comment">        */</span>
<a name="l03588"></a>03588         <span class="keywordflow">if</span> (rad == 0) {
<a name="l03589"></a>03589                 <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ae6f8690e5c5a85d3263c8e16727b34ef" title="Pixel draw with blending enabled if a&lt;255.">pixelColor</a>(dst, x, y, color));
<a name="l03590"></a>03590         }
<a name="l03591"></a>03591 
<a name="l03592"></a>03592         <span class="comment">/*</span>
<a name="l03593"></a>03593 <span class="comment">        * Get circle and clipping boundary and </span>
<a name="l03594"></a>03594 <span class="comment">        * test if bounding box of circle is visible </span>
<a name="l03595"></a>03595 <span class="comment">        */</span>
<a name="l03596"></a>03596         x2 = x + rad;
<a name="l03597"></a>03597         left = dst-&gt;clip_rect.x;
<a name="l03598"></a>03598         <span class="keywordflow">if</span> (x2&lt;left) {
<a name="l03599"></a>03599                 <span class="keywordflow">return</span>(0);
<a name="l03600"></a>03600         } 
<a name="l03601"></a>03601         x1 = x - rad;
<a name="l03602"></a>03602         right = dst-&gt;clip_rect.x + dst-&gt;clip_rect.w - 1;
<a name="l03603"></a>03603         <span class="keywordflow">if</span> (x1&gt;right) {
<a name="l03604"></a>03604                 <span class="keywordflow">return</span>(0);
<a name="l03605"></a>03605         } 
<a name="l03606"></a>03606         y2 = y + rad;
<a name="l03607"></a>03607         top = dst-&gt;clip_rect.y;
<a name="l03608"></a>03608         <span class="keywordflow">if</span> (y2&lt;top) {
<a name="l03609"></a>03609                 <span class="keywordflow">return</span>(0);
<a name="l03610"></a>03610         } 
<a name="l03611"></a>03611         y1 = y - rad;
<a name="l03612"></a>03612         bottom = dst-&gt;clip_rect.y + dst-&gt;clip_rect.h - 1;
<a name="l03613"></a>03613         <span class="keywordflow">if</span> (y1&gt;bottom) {
<a name="l03614"></a>03614                 <span class="keywordflow">return</span>(0);
<a name="l03615"></a>03615         } 
<a name="l03616"></a>03616 
<a name="l03617"></a>03617         <span class="comment">/*</span>
<a name="l03618"></a>03618 <span class="comment">        * Draw </span>
<a name="l03619"></a>03619 <span class="comment">        */</span>
<a name="l03620"></a>03620         result = 0;
<a name="l03621"></a>03621         <span class="keywordflow">do</span> {
<a name="l03622"></a>03622                 xpcx = x + cx;
<a name="l03623"></a>03623                 xmcx = x - cx;
<a name="l03624"></a>03624                 xpcy = x + cy;
<a name="l03625"></a>03625                 xmcy = x - cy;
<a name="l03626"></a>03626                 <span class="keywordflow">if</span> (ocy != cy) {
<a name="l03627"></a>03627                         <span class="keywordflow">if</span> (cy &gt; 0) {
<a name="l03628"></a>03628                                 ypcy = y + cy;
<a name="l03629"></a>03629                                 ymcy = y - cy;
<a name="l03630"></a>03630                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, xmcx, xpcx, ypcy, color);
<a name="l03631"></a>03631                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, xmcx, xpcx, ymcy, color);
<a name="l03632"></a>03632                         } <span class="keywordflow">else</span> {
<a name="l03633"></a>03633                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, xmcx, xpcx, y, color);
<a name="l03634"></a>03634                         }
<a name="l03635"></a>03635                         ocy = cy;
<a name="l03636"></a>03636                 }
<a name="l03637"></a>03637                 <span class="keywordflow">if</span> (ocx != cx) {
<a name="l03638"></a>03638                         <span class="keywordflow">if</span> (cx != cy) {
<a name="l03639"></a>03639                                 <span class="keywordflow">if</span> (cx &gt; 0) {
<a name="l03640"></a>03640                                         ypcx = y + cx;
<a name="l03641"></a>03641                                         ymcx = y - cx;
<a name="l03642"></a>03642                                         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, xmcy, xpcy, ymcx, color);
<a name="l03643"></a>03643                                         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, xmcy, xpcy, ypcx, color);
<a name="l03644"></a>03644                                 } <span class="keywordflow">else</span> {
<a name="l03645"></a>03645                                         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, xmcy, xpcy, y, color);
<a name="l03646"></a>03646                                 }
<a name="l03647"></a>03647                         }
<a name="l03648"></a>03648                         ocx = cx;
<a name="l03649"></a>03649                 }
<a name="l03650"></a>03650                 <span class="comment">/*</span>
<a name="l03651"></a>03651 <span class="comment">                * Update </span>
<a name="l03652"></a>03652 <span class="comment">                */</span>
<a name="l03653"></a>03653                 <span class="keywordflow">if</span> (df &lt; 0) {
<a name="l03654"></a>03654                         df += d_e;
<a name="l03655"></a>03655                         d_e += 2;
<a name="l03656"></a>03656                         d_se += 2;
<a name="l03657"></a>03657                 } <span class="keywordflow">else</span> {
<a name="l03658"></a>03658                         df += d_se;
<a name="l03659"></a>03659                         d_e += 2;
<a name="l03660"></a>03660                         d_se += 4;
<a name="l03661"></a>03661                         cy--;
<a name="l03662"></a>03662                 }
<a name="l03663"></a>03663                 cx++;
<a name="l03664"></a>03664         } <span class="keywordflow">while</span> (cx &lt;= cy);
<a name="l03665"></a>03665 
<a name="l03666"></a>03666         <span class="keywordflow">return</span> (result);
<a name="l03667"></a>03667 }
<a name="l03668"></a>03668 
<a name="l03683"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a01af970ce0be38cea9884bc6f816c984">03683</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a562ba6b18fb70547cd50cb3bb0f70272" title="Draw filled circle with blending.">filledCircleRGBA</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l03684"></a>03684 {
<a name="l03685"></a>03685         <span class="comment">/*</span>
<a name="l03686"></a>03686 <span class="comment">        * Draw </span>
<a name="l03687"></a>03687 <span class="comment">        */</span>
<a name="l03688"></a>03688         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a39147d1282ec814a1b9e31243aad0359" title="Draw filled circle with blending.">filledCircleColor</a>
<a name="l03689"></a>03689                 (dst, x, y, rad, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a));
<a name="l03690"></a>03690 }
<a name="l03691"></a>03691 
<a name="l03692"></a>03692 <span class="comment">/* ----- Ellipse */</span>
<a name="l03693"></a>03693 
<a name="l03709"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a8b46f389c626806e7a1ec148f0980737">03709</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a476cff7702f4be9090871e35859782f0" title="Draw ellipse with blending.">ellipseColor</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color)
<a name="l03710"></a>03710 {
<a name="l03711"></a>03711         Sint16 left, right, top, bottom;
<a name="l03712"></a>03712         <span class="keywordtype">int</span> result;
<a name="l03713"></a>03713         Sint16 x1, y1, x2, y2;
<a name="l03714"></a>03714         <span class="keywordtype">int</span> ix, iy;
<a name="l03715"></a>03715         <span class="keywordtype">int</span> h, i, j, k;
<a name="l03716"></a>03716         <span class="keywordtype">int</span> oh, oi, oj, ok;
<a name="l03717"></a>03717         <span class="keywordtype">int</span> xmh, xph, ypk, ymk;
<a name="l03718"></a>03718         <span class="keywordtype">int</span> xmi, xpi, ymj, ypj;
<a name="l03719"></a>03719         <span class="keywordtype">int</span> xmj, xpj, ymi, ypi;
<a name="l03720"></a>03720         <span class="keywordtype">int</span> xmk, xpk, ymh, yph;
<a name="l03721"></a>03721         Uint8 *colorptr;
<a name="l03722"></a>03722 
<a name="l03723"></a>03723         <span class="comment">/*</span>
<a name="l03724"></a>03724 <span class="comment">        * Check visibility of clipping rectangle</span>
<a name="l03725"></a>03725 <span class="comment">        */</span>
<a name="l03726"></a>03726         <span class="keywordflow">if</span> ((dst-&gt;clip_rect.w==0) || (dst-&gt;clip_rect.h==0)) {
<a name="l03727"></a>03727                 <span class="keywordflow">return</span>(0);
<a name="l03728"></a>03728         }
<a name="l03729"></a>03729 
<a name="l03730"></a>03730         <span class="comment">/*</span>
<a name="l03731"></a>03731 <span class="comment">        * Sanity check radii </span>
<a name="l03732"></a>03732 <span class="comment">        */</span>
<a name="l03733"></a>03733         <span class="keywordflow">if</span> ((rx &lt; 0) || (ry &lt; 0)) {
<a name="l03734"></a>03734                 <span class="keywordflow">return</span> (-1);
<a name="l03735"></a>03735         }
<a name="l03736"></a>03736 
<a name="l03737"></a>03737         <span class="comment">/*</span>
<a name="l03738"></a>03738 <span class="comment">        * Special case for rx=0 - draw a vline </span>
<a name="l03739"></a>03739 <span class="comment">        */</span>
<a name="l03740"></a>03740         <span class="keywordflow">if</span> (rx == 0) {
<a name="l03741"></a>03741                 <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a9b45060155a19fee24f998d7790f1d67" title="Draw vertical line with blending.">vlineColor</a>(dst, x, y - ry, y + ry, color));
<a name="l03742"></a>03742         }
<a name="l03743"></a>03743         <span class="comment">/*</span>
<a name="l03744"></a>03744 <span class="comment">        * Special case for ry=0 - draw a hline </span>
<a name="l03745"></a>03745 <span class="comment">        */</span>
<a name="l03746"></a>03746         <span class="keywordflow">if</span> (ry == 0) {
<a name="l03747"></a>03747                 <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, x - rx, x + rx, y, color));
<a name="l03748"></a>03748         }
<a name="l03749"></a>03749 
<a name="l03750"></a>03750         <span class="comment">/*</span>
<a name="l03751"></a>03751 <span class="comment">        * Get circle and clipping boundary and </span>
<a name="l03752"></a>03752 <span class="comment">        * test if bounding box of circle is visible </span>
<a name="l03753"></a>03753 <span class="comment">        */</span>
<a name="l03754"></a>03754         x2 = x + rx;
<a name="l03755"></a>03755         left = dst-&gt;clip_rect.x;
<a name="l03756"></a>03756         <span class="keywordflow">if</span> (x2&lt;left) {
<a name="l03757"></a>03757                 <span class="keywordflow">return</span>(0);
<a name="l03758"></a>03758         } 
<a name="l03759"></a>03759         x1 = x - rx;
<a name="l03760"></a>03760         right = dst-&gt;clip_rect.x + dst-&gt;clip_rect.w - 1;
<a name="l03761"></a>03761         <span class="keywordflow">if</span> (x1&gt;right) {
<a name="l03762"></a>03762                 <span class="keywordflow">return</span>(0);
<a name="l03763"></a>03763         } 
<a name="l03764"></a>03764         y2 = y + ry;
<a name="l03765"></a>03765         top = dst-&gt;clip_rect.y;
<a name="l03766"></a>03766         <span class="keywordflow">if</span> (y2&lt;top) {
<a name="l03767"></a>03767                 <span class="keywordflow">return</span>(0);
<a name="l03768"></a>03768         } 
<a name="l03769"></a>03769         y1 = y - ry;
<a name="l03770"></a>03770         bottom = dst-&gt;clip_rect.y + dst-&gt;clip_rect.h - 1;
<a name="l03771"></a>03771         <span class="keywordflow">if</span> (y1&gt;bottom) {
<a name="l03772"></a>03772                 <span class="keywordflow">return</span>(0);
<a name="l03773"></a>03773         } 
<a name="l03774"></a>03774 
<a name="l03775"></a>03775         <span class="comment">/*</span>
<a name="l03776"></a>03776 <span class="comment">        * Init vars </span>
<a name="l03777"></a>03777 <span class="comment">        */</span>
<a name="l03778"></a>03778         oh = oi = oj = ok = 0xFFFF;
<a name="l03779"></a>03779 
<a name="l03780"></a>03780         <span class="comment">/*</span>
<a name="l03781"></a>03781 <span class="comment">        * Draw </span>
<a name="l03782"></a>03782 <span class="comment">        */</span>
<a name="l03783"></a>03783         result = 0;
<a name="l03784"></a>03784 
<a name="l03785"></a>03785         <span class="comment">/* Lock surface */</span>
<a name="l03786"></a>03786         <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l03787"></a>03787                 <span class="keywordflow">if</span> (SDL_LockSurface(dst) &lt; 0) {
<a name="l03788"></a>03788                         <span class="keywordflow">return</span> (-1);
<a name="l03789"></a>03789                 }
<a name="l03790"></a>03790         }
<a name="l03791"></a>03791 
<a name="l03792"></a>03792         <span class="comment">/*</span>
<a name="l03793"></a>03793 <span class="comment">        * Check alpha </span>
<a name="l03794"></a>03794 <span class="comment">        */</span>
<a name="l03795"></a>03795         <span class="keywordflow">if</span> ((color &amp; 255) == 255) {
<a name="l03796"></a>03796 
<a name="l03797"></a>03797                 <span class="comment">/*</span>
<a name="l03798"></a>03798 <span class="comment">                * No Alpha - direct memory writes </span>
<a name="l03799"></a>03799 <span class="comment">                */</span>
<a name="l03800"></a>03800 
<a name="l03801"></a>03801                 <span class="comment">/*</span>
<a name="l03802"></a>03802 <span class="comment">                * Setup color </span>
<a name="l03803"></a>03803 <span class="comment">                */</span>
<a name="l03804"></a>03804                 colorptr = (Uint8 *) &amp; color;
<a name="l03805"></a>03805                 <span class="keywordflow">if</span> (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
<a name="l03806"></a>03806                         color = SDL_MapRGBA(dst-&gt;format, colorptr[0], colorptr[1], colorptr[2], colorptr[3]);
<a name="l03807"></a>03807                 } <span class="keywordflow">else</span> {
<a name="l03808"></a>03808                         color = SDL_MapRGBA(dst-&gt;format, colorptr[3], colorptr[2], colorptr[1], colorptr[0]);
<a name="l03809"></a>03809                 }
<a name="l03810"></a>03810 
<a name="l03811"></a>03811 
<a name="l03812"></a>03812                 <span class="keywordflow">if</span> (rx &gt; ry) {
<a name="l03813"></a>03813                         ix = 0;
<a name="l03814"></a>03814                         iy = rx * 64;
<a name="l03815"></a>03815 
<a name="l03816"></a>03816                         <span class="keywordflow">do</span> {
<a name="l03817"></a>03817                                 h = (ix + 32) &gt;&gt; 6;
<a name="l03818"></a>03818                                 i = (iy + 32) &gt;&gt; 6;
<a name="l03819"></a>03819                                 j = (h * ry) / rx;
<a name="l03820"></a>03820                                 k = (i * ry) / rx;
<a name="l03821"></a>03821 
<a name="l03822"></a>03822                                 <span class="keywordflow">if</span> (((ok != k) &amp;&amp; (oj != k)) || ((oj != j) &amp;&amp; (ok != j)) || (k != j)) {
<a name="l03823"></a>03823                                         xph = x + h;
<a name="l03824"></a>03824                                         xmh = x - h;
<a name="l03825"></a>03825                                         <span class="keywordflow">if</span> (k &gt; 0) {
<a name="l03826"></a>03826                                                 ypk = y + k;
<a name="l03827"></a>03827                                                 ymk = y - k;
<a name="l03828"></a>03828                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xmh, ypk, color);
<a name="l03829"></a>03829                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xph, ypk, color);
<a name="l03830"></a>03830                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xmh, ymk, color);
<a name="l03831"></a>03831                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xph, ymk, color);
<a name="l03832"></a>03832                                         } <span class="keywordflow">else</span> {
<a name="l03833"></a>03833                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xmh, y, color);
<a name="l03834"></a>03834                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xph, y, color);
<a name="l03835"></a>03835                                         }
<a name="l03836"></a>03836                                         ok = k;
<a name="l03837"></a>03837                                         xpi = x + i;
<a name="l03838"></a>03838                                         xmi = x - i;
<a name="l03839"></a>03839                                         <span class="keywordflow">if</span> (j &gt; 0) {
<a name="l03840"></a>03840                                                 ypj = y + j;
<a name="l03841"></a>03841                                                 ymj = y - j;
<a name="l03842"></a>03842                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xmi, ypj, color);
<a name="l03843"></a>03843                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xpi, ypj, color);
<a name="l03844"></a>03844                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xmi, ymj, color);
<a name="l03845"></a>03845                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xpi, ymj, color);
<a name="l03846"></a>03846                                         } <span class="keywordflow">else</span> {
<a name="l03847"></a>03847                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xmi, y, color);
<a name="l03848"></a>03848                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xpi, y, color);
<a name="l03849"></a>03849                                         }
<a name="l03850"></a>03850                                         oj = j;
<a name="l03851"></a>03851                                 }
<a name="l03852"></a>03852 
<a name="l03853"></a>03853                                 ix = ix + iy / rx;
<a name="l03854"></a>03854                                 iy = iy - ix / rx;
<a name="l03855"></a>03855 
<a name="l03856"></a>03856                         } <span class="keywordflow">while</span> (i &gt; h);
<a name="l03857"></a>03857                 } <span class="keywordflow">else</span> {
<a name="l03858"></a>03858                         ix = 0;
<a name="l03859"></a>03859                         iy = ry * 64;
<a name="l03860"></a>03860 
<a name="l03861"></a>03861                         <span class="keywordflow">do</span> {
<a name="l03862"></a>03862                                 h = (ix + 32) &gt;&gt; 6;
<a name="l03863"></a>03863                                 i = (iy + 32) &gt;&gt; 6;
<a name="l03864"></a>03864                                 j = (h * rx) / ry;
<a name="l03865"></a>03865                                 k = (i * rx) / ry;
<a name="l03866"></a>03866 
<a name="l03867"></a>03867                                 <span class="keywordflow">if</span> (((oi != i) &amp;&amp; (oh != i)) || ((oh != h) &amp;&amp; (oi != h) &amp;&amp; (i != h))) {
<a name="l03868"></a>03868                                         xmj = x - j;
<a name="l03869"></a>03869                                         xpj = x + j;
<a name="l03870"></a>03870                                         <span class="keywordflow">if</span> (i &gt; 0) {
<a name="l03871"></a>03871                                                 ypi = y + i;
<a name="l03872"></a>03872                                                 ymi = y - i;
<a name="l03873"></a>03873                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xmj, ypi, color);
<a name="l03874"></a>03874                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xpj, ypi, color);
<a name="l03875"></a>03875                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xmj, ymi, color);
<a name="l03876"></a>03876                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xpj, ymi, color);
<a name="l03877"></a>03877                                         } <span class="keywordflow">else</span> {
<a name="l03878"></a>03878                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xmj, y, color);
<a name="l03879"></a>03879                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xpj, y, color);
<a name="l03880"></a>03880                                         }
<a name="l03881"></a>03881                                         oi = i;
<a name="l03882"></a>03882                                         xmk = x - k;
<a name="l03883"></a>03883                                         xpk = x + k;
<a name="l03884"></a>03884                                         <span class="keywordflow">if</span> (h &gt; 0) {
<a name="l03885"></a>03885                                                 yph = y + h;
<a name="l03886"></a>03886                                                 ymh = y - h;
<a name="l03887"></a>03887                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xmk, yph, color);
<a name="l03888"></a>03888                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xpk, yph, color);
<a name="l03889"></a>03889                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xmk, ymh, color);
<a name="l03890"></a>03890                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xpk, ymh, color);
<a name="l03891"></a>03891                                         } <span class="keywordflow">else</span> {
<a name="l03892"></a>03892                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xmk, y, color);
<a name="l03893"></a>03893                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a011e3e26d7216998357fb1a089f8f742" title="Internal pixel drawing - fast, no blending, no locking, clipping.">fastPixelColorNolock</a>(dst, xpk, y, color);
<a name="l03894"></a>03894                                         }
<a name="l03895"></a>03895                                         oh = h;
<a name="l03896"></a>03896                                 }
<a name="l03897"></a>03897 
<a name="l03898"></a>03898                                 ix = ix + iy / ry;
<a name="l03899"></a>03899                                 iy = iy - ix / ry;
<a name="l03900"></a>03900 
<a name="l03901"></a>03901                         } <span class="keywordflow">while</span> (i &gt; h);
<a name="l03902"></a>03902                 }
<a name="l03903"></a>03903 
<a name="l03904"></a>03904         } <span class="keywordflow">else</span> {
<a name="l03905"></a>03905 
<a name="l03906"></a>03906                 <span class="keywordflow">if</span> (rx &gt; ry) {
<a name="l03907"></a>03907                         ix = 0;
<a name="l03908"></a>03908                         iy = rx * 64;
<a name="l03909"></a>03909 
<a name="l03910"></a>03910                         <span class="keywordflow">do</span> {
<a name="l03911"></a>03911                                 h = (ix + 32) &gt;&gt; 6;
<a name="l03912"></a>03912                                 i = (iy + 32) &gt;&gt; 6;
<a name="l03913"></a>03913                                 j = (h * ry) / rx;
<a name="l03914"></a>03914                                 k = (i * ry) / rx;
<a name="l03915"></a>03915 
<a name="l03916"></a>03916                                 <span class="keywordflow">if</span> (((ok != k) &amp;&amp; (oj != k)) || ((oj != j) &amp;&amp; (ok != j)) || (k != j)) {
<a name="l03917"></a>03917                                         xph = x + h;
<a name="l03918"></a>03918                                         xmh = x - h;
<a name="l03919"></a>03919                                         <span class="keywordflow">if</span> (k &gt; 0) {
<a name="l03920"></a>03920                                                 ypk = y + k;
<a name="l03921"></a>03921                                                 ymk = y - k;
<a name="l03922"></a>03922                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xmh, ypk, color);
<a name="l03923"></a>03923                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xph, ypk, color);
<a name="l03924"></a>03924                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xmh, ymk, color);
<a name="l03925"></a>03925                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xph, ymk, color);
<a name="l03926"></a>03926                                         } <span class="keywordflow">else</span> {
<a name="l03927"></a>03927                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xmh, y, color);
<a name="l03928"></a>03928                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xph, y, color);
<a name="l03929"></a>03929                                         }
<a name="l03930"></a>03930                                         ok = k;
<a name="l03931"></a>03931                                         xpi = x + i;
<a name="l03932"></a>03932                                         xmi = x - i;
<a name="l03933"></a>03933                                         <span class="keywordflow">if</span> (j &gt; 0) {
<a name="l03934"></a>03934                                                 ypj = y + j;
<a name="l03935"></a>03935                                                 ymj = y - j;
<a name="l03936"></a>03936                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xmi, ypj, color);
<a name="l03937"></a>03937                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xpi, ypj, color);
<a name="l03938"></a>03938                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xmi, ymj, color);
<a name="l03939"></a>03939                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae6f8690e5c5a85d3263c8e16727b34ef" title="Pixel draw with blending enabled if a&lt;255.">pixelColor</a>(dst, xpi, ymj, color);
<a name="l03940"></a>03940                                         } <span class="keywordflow">else</span> {
<a name="l03941"></a>03941                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xmi, y, color);
<a name="l03942"></a>03942                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xpi, y, color);
<a name="l03943"></a>03943                                         }
<a name="l03944"></a>03944                                         oj = j;
<a name="l03945"></a>03945                                 }
<a name="l03946"></a>03946 
<a name="l03947"></a>03947                                 ix = ix + iy / rx;
<a name="l03948"></a>03948                                 iy = iy - ix / rx;
<a name="l03949"></a>03949 
<a name="l03950"></a>03950                         } <span class="keywordflow">while</span> (i &gt; h);
<a name="l03951"></a>03951                 } <span class="keywordflow">else</span> {
<a name="l03952"></a>03952                         ix = 0;
<a name="l03953"></a>03953                         iy = ry * 64;
<a name="l03954"></a>03954 
<a name="l03955"></a>03955                         <span class="keywordflow">do</span> {
<a name="l03956"></a>03956                                 h = (ix + 32) &gt;&gt; 6;
<a name="l03957"></a>03957                                 i = (iy + 32) &gt;&gt; 6;
<a name="l03958"></a>03958                                 j = (h * rx) / ry;
<a name="l03959"></a>03959                                 k = (i * rx) / ry;
<a name="l03960"></a>03960 
<a name="l03961"></a>03961                                 <span class="keywordflow">if</span> (((oi != i) &amp;&amp; (oh != i)) || ((oh != h) &amp;&amp; (oi != h) &amp;&amp; (i != h))) {
<a name="l03962"></a>03962                                         xmj = x - j;
<a name="l03963"></a>03963                                         xpj = x + j;
<a name="l03964"></a>03964                                         <span class="keywordflow">if</span> (i &gt; 0) {
<a name="l03965"></a>03965                                                 ypi = y + i;
<a name="l03966"></a>03966                                                 ymi = y - i;
<a name="l03967"></a>03967                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xmj, ypi, color);
<a name="l03968"></a>03968                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xpj, ypi, color);
<a name="l03969"></a>03969                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xmj, ymi, color);
<a name="l03970"></a>03970                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xpj, ymi, color);
<a name="l03971"></a>03971                                         } <span class="keywordflow">else</span> {
<a name="l03972"></a>03972                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xmj, y, color);
<a name="l03973"></a>03973                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xpj, y, color);
<a name="l03974"></a>03974                                         }
<a name="l03975"></a>03975                                         oi = i;
<a name="l03976"></a>03976                                         xmk = x - k;
<a name="l03977"></a>03977                                         xpk = x + k;
<a name="l03978"></a>03978                                         <span class="keywordflow">if</span> (h &gt; 0) {
<a name="l03979"></a>03979                                                 yph = y + h;
<a name="l03980"></a>03980                                                 ymh = y - h;
<a name="l03981"></a>03981                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xmk, yph, color);
<a name="l03982"></a>03982                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xpk, yph, color);
<a name="l03983"></a>03983                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xmk, ymh, color);
<a name="l03984"></a>03984                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xpk, ymh, color);
<a name="l03985"></a>03985                                         } <span class="keywordflow">else</span> {
<a name="l03986"></a>03986                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xmk, y, color);
<a name="l03987"></a>03987                                                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a> (dst, xpk, y, color);
<a name="l03988"></a>03988                                         }
<a name="l03989"></a>03989                                         oh = h;
<a name="l03990"></a>03990                                 }
<a name="l03991"></a>03991 
<a name="l03992"></a>03992                                 ix = ix + iy / ry;
<a name="l03993"></a>03993                                 iy = iy - ix / ry;
<a name="l03994"></a>03994 
<a name="l03995"></a>03995                         } <span class="keywordflow">while</span> (i &gt; h);
<a name="l03996"></a>03996                 }
<a name="l03997"></a>03997 
<a name="l03998"></a>03998         }                               <span class="comment">/* Alpha check */</span>
<a name="l03999"></a>03999 
<a name="l04000"></a>04000         <span class="comment">/* Unlock surface */</span>
<a name="l04001"></a>04001         <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l04002"></a>04002                 SDL_UnlockSurface(dst);
<a name="l04003"></a>04003         }
<a name="l04004"></a>04004 
<a name="l04005"></a>04005         <span class="keywordflow">return</span> (result);
<a name="l04006"></a>04006 }
<a name="l04007"></a>04007 
<a name="l04023"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a523156891302420d2296b1a302c1fc2b">04023</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a18c8a26c9009482eec40f9f4a6945fd1" title="Draw ellipse with blending.">ellipseRGBA</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l04024"></a>04024 {
<a name="l04025"></a>04025         <span class="comment">/*</span>
<a name="l04026"></a>04026 <span class="comment">        * Draw </span>
<a name="l04027"></a>04027 <span class="comment">        */</span>
<a name="l04028"></a>04028         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a476cff7702f4be9090871e35859782f0" title="Draw ellipse with blending.">ellipseColor</a>(dst, x, y, rx, ry, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a));
<a name="l04029"></a>04029 }
<a name="l04030"></a>04030 
<a name="l04031"></a>04031 <span class="comment">/* ----- AA Ellipse */</span>
<a name="l04032"></a>04032 
<a name="l04033"></a>04033 <span class="comment">/* Windows targets do not have lrint, so provide a local inline version */</span>
<a name="l04034"></a>04034 <span class="preprocessor">#if defined(_MSC_VER)</span>
<a name="l04035"></a>04035 <span class="preprocessor"></span><span class="comment">/* Detect 64bit and use intrinsic version */</span>
<a name="l04036"></a>04036 <span class="preprocessor">#ifdef _M_X64</span>
<a name="l04037"></a>04037 <span class="preprocessor"></span><span class="preprocessor">#include &lt;emmintrin.h&gt;</span>
<a name="l04038"></a>04038 <span class="keyword">static</span> __inline <span class="keywordtype">long</span> 
<a name="l04039"></a>04039         lrint(<span class="keywordtype">float</span> f) 
<a name="l04040"></a>04040 {
<a name="l04041"></a>04041         <span class="keywordflow">return</span> _mm_cvtss_si32(_mm_load_ss(&amp;f));
<a name="l04042"></a>04042 }
<a name="l04043"></a>04043 <span class="preprocessor">#elif defined(_M_IX86)</span>
<a name="l04044"></a>04044 <span class="preprocessor"></span>__inline <span class="keywordtype">long</span> <span class="keywordtype">int</span>
<a name="l04045"></a>04045         lrint (<span class="keywordtype">double</span> flt)
<a name="l04046"></a>04046 {       
<a name="l04047"></a>04047         <span class="keywordtype">int</span> intgr;
<a name="l04048"></a>04048         _asm
<a name="l04049"></a>04049         {
<a name="l04050"></a>04050                 fld flt
<a name="l04051"></a>04051                         fistp intgr
<a name="l04052"></a>04052         };
<a name="l04053"></a>04053         <span class="keywordflow">return</span> intgr;
<a name="l04054"></a>04054 }
<a name="l04055"></a>04055 <span class="preprocessor">#elif defined(_M_ARM)</span>
<a name="l04056"></a>04056 <span class="preprocessor"></span><span class="preprocessor">#include &lt;armintr.h&gt;</span>
<a name="l04057"></a>04057 <span class="preprocessor">#pragma warning(push)</span>
<a name="l04058"></a>04058 <span class="preprocessor"></span><span class="preprocessor">#pragma warning(disable: 4716)</span>
<a name="l04059"></a>04059 <span class="preprocessor"></span>__declspec(naked) long <span class="keywordtype">int</span>
<a name="l04060"></a>04060         lrint (<span class="keywordtype">double</span> flt)
<a name="l04061"></a>04061 {
<a name="l04062"></a>04062         __emit(0xEC410B10); <span class="comment">// fmdrr  d0, r0, r1</span>
<a name="l04063"></a>04063         __emit(0xEEBD0B40); <span class="comment">// ftosid s0, d0</span>
<a name="l04064"></a>04064         __emit(0xEE100A10); <span class="comment">// fmrs   r0, s0</span>
<a name="l04065"></a>04065         __emit(0xE12FFF1E); <span class="comment">// bx     lr</span>
<a name="l04066"></a>04066 }
<a name="l04067"></a>04067 <span class="preprocessor">#pragma warning(pop)</span>
<a name="l04068"></a>04068 <span class="preprocessor"></span><span class="preprocessor">#else</span>
<a name="l04069"></a>04069 <span class="preprocessor"></span><span class="preprocessor">#error lrint needed for MSVC on non X86/AMD64/ARM targets.</span>
<a name="l04070"></a>04070 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l04071"></a>04071 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l04072"></a>04072 <span class="preprocessor"></span>
<a name="l04088"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a6edf60c54acc964cbb47ddefc6c0d450">04088</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a1c7d20dcba8e0d7ce483f4c854c438be" title="Draw anti-aliased ellipse with blending.">aaellipseColor</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color)
<a name="l04089"></a>04089 {
<a name="l04090"></a>04090         Sint16 left, right, top, bottom;
<a name="l04091"></a>04091         Sint16 x1,y1,x2,y2;
<a name="l04092"></a>04092         <span class="keywordtype">int</span> i;
<a name="l04093"></a>04093         <span class="keywordtype">int</span> a2, b2, ds, dt, dxt, t, s, d;
<a name="l04094"></a>04094         Sint16 xp, yp, xs, ys, dyt, od, xx, yy, xc2, yc2;
<a name="l04095"></a>04095         <span class="keywordtype">float</span> cp;
<a name="l04096"></a>04096         <span class="keywordtype">double</span> sab;
<a name="l04097"></a>04097         Uint8 weight, iweight;
<a name="l04098"></a>04098         <span class="keywordtype">int</span> result;
<a name="l04099"></a>04099 
<a name="l04100"></a>04100         <span class="comment">/*</span>
<a name="l04101"></a>04101 <span class="comment">        * Check visibility of clipping rectangle</span>
<a name="l04102"></a>04102 <span class="comment">        */</span>
<a name="l04103"></a>04103         <span class="keywordflow">if</span> ((dst-&gt;clip_rect.w==0) || (dst-&gt;clip_rect.h==0)) {
<a name="l04104"></a>04104                 <span class="keywordflow">return</span>(0);
<a name="l04105"></a>04105         }
<a name="l04106"></a>04106 
<a name="l04107"></a>04107         <span class="comment">/*</span>
<a name="l04108"></a>04108 <span class="comment">        * Sanity check radii </span>
<a name="l04109"></a>04109 <span class="comment">        */</span>
<a name="l04110"></a>04110         <span class="keywordflow">if</span> ((rx &lt; 0) || (ry &lt; 0)) {
<a name="l04111"></a>04111                 <span class="keywordflow">return</span> (-1);
<a name="l04112"></a>04112         }
<a name="l04113"></a>04113 
<a name="l04114"></a>04114         <span class="comment">/*</span>
<a name="l04115"></a>04115 <span class="comment">        * Special case for rx=0 - draw a vline </span>
<a name="l04116"></a>04116 <span class="comment">        */</span>
<a name="l04117"></a>04117         <span class="keywordflow">if</span> (rx == 0) {
<a name="l04118"></a>04118                 <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a9b45060155a19fee24f998d7790f1d67" title="Draw vertical line with blending.">vlineColor</a>(dst, x, y - ry, y + ry, color));
<a name="l04119"></a>04119         }
<a name="l04120"></a>04120         <span class="comment">/*</span>
<a name="l04121"></a>04121 <span class="comment">        * Special case for ry=0 - draw an hline </span>
<a name="l04122"></a>04122 <span class="comment">        */</span>
<a name="l04123"></a>04123         <span class="keywordflow">if</span> (ry == 0) {
<a name="l04124"></a>04124                 <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, x - rx, x + rx, y, color));
<a name="l04125"></a>04125         }
<a name="l04126"></a>04126 
<a name="l04127"></a>04127         <span class="comment">/*</span>
<a name="l04128"></a>04128 <span class="comment">        * Get circle and clipping boundary and </span>
<a name="l04129"></a>04129 <span class="comment">        * test if bounding box of circle is visible </span>
<a name="l04130"></a>04130 <span class="comment">        */</span>
<a name="l04131"></a>04131         x2 = x + rx;
<a name="l04132"></a>04132         left = dst-&gt;clip_rect.x;
<a name="l04133"></a>04133         <span class="keywordflow">if</span> (x2&lt;left) {
<a name="l04134"></a>04134                 <span class="keywordflow">return</span>(0);
<a name="l04135"></a>04135         } 
<a name="l04136"></a>04136         x1 = x - rx;
<a name="l04137"></a>04137         right = dst-&gt;clip_rect.x + dst-&gt;clip_rect.w - 1;
<a name="l04138"></a>04138         <span class="keywordflow">if</span> (x1&gt;right) {
<a name="l04139"></a>04139                 <span class="keywordflow">return</span>(0);
<a name="l04140"></a>04140         } 
<a name="l04141"></a>04141         y2 = y + ry;
<a name="l04142"></a>04142         top = dst-&gt;clip_rect.y;
<a name="l04143"></a>04143         <span class="keywordflow">if</span> (y2&lt;top) {
<a name="l04144"></a>04144                 <span class="keywordflow">return</span>(0);
<a name="l04145"></a>04145         } 
<a name="l04146"></a>04146         y1 = y - ry;
<a name="l04147"></a>04147         bottom = dst-&gt;clip_rect.y + dst-&gt;clip_rect.h - 1;
<a name="l04148"></a>04148         <span class="keywordflow">if</span> (y1&gt;bottom) {
<a name="l04149"></a>04149                 <span class="keywordflow">return</span>(0);
<a name="l04150"></a>04150         } 
<a name="l04151"></a>04151 
<a name="l04152"></a>04152         <span class="comment">/* Variable setup */</span>
<a name="l04153"></a>04153         a2 = rx * rx;
<a name="l04154"></a>04154         b2 = ry * ry;
<a name="l04155"></a>04155 
<a name="l04156"></a>04156         ds = 2 * a2;
<a name="l04157"></a>04157         dt = 2 * b2;
<a name="l04158"></a>04158 
<a name="l04159"></a>04159         xc2 = 2 * x;
<a name="l04160"></a>04160         yc2 = 2 * y;
<a name="l04161"></a>04161 
<a name="l04162"></a>04162         sab = sqrt((<span class="keywordtype">double</span>)(a2 + b2));
<a name="l04163"></a>04163         od = (Sint16)lrint(sab*0.01) + 1; <span class="comment">/* introduce some overdraw */</span>
<a name="l04164"></a>04164         dxt = (Sint16)lrint((<span class="keywordtype">double</span>)a2 / sab) + od;
<a name="l04165"></a>04165 
<a name="l04166"></a>04166         t = 0;
<a name="l04167"></a>04167         s = -2 * a2 * ry;
<a name="l04168"></a>04168         d = 0;
<a name="l04169"></a>04169 
<a name="l04170"></a>04170         xp = x;
<a name="l04171"></a>04171         yp = y - ry;
<a name="l04172"></a>04172 
<a name="l04173"></a>04173         <span class="comment">/* Lock surface */</span>
<a name="l04174"></a>04174         <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l04175"></a>04175                 <span class="keywordflow">if</span> (SDL_LockSurface(dst) &lt; 0) {
<a name="l04176"></a>04176                         <span class="keywordflow">return</span> (-1);
<a name="l04177"></a>04177                 }
<a name="l04178"></a>04178         }
<a name="l04179"></a>04179 
<a name="l04180"></a>04180         <span class="comment">/* Draw */</span>
<a name="l04181"></a>04181         result = 0;
<a name="l04182"></a>04182 
<a name="l04183"></a>04183         <span class="comment">/* &quot;End points&quot; */</span>
<a name="l04184"></a>04184         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(dst, xp, yp, color);
<a name="l04185"></a>04185         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(dst, xc2 - xp, yp, color);
<a name="l04186"></a>04186         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(dst, xp, yc2 - yp, color);
<a name="l04187"></a>04187         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(dst, xc2 - xp, yc2 - yp, color);
<a name="l04188"></a>04188 
<a name="l04189"></a>04189         <span class="keywordflow">for</span> (i = 1; i &lt;= dxt; i++) {
<a name="l04190"></a>04190                 xp--;
<a name="l04191"></a>04191                 d += t - b2;
<a name="l04192"></a>04192 
<a name="l04193"></a>04193                 <span class="keywordflow">if</span> (d &gt;= 0)
<a name="l04194"></a>04194                         ys = yp - 1;
<a name="l04195"></a>04195                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((d - s - a2) &gt; 0) {
<a name="l04196"></a>04196                         <span class="keywordflow">if</span> ((2 * d - s - a2) &gt;= 0)
<a name="l04197"></a>04197                                 ys = yp + 1;
<a name="l04198"></a>04198                         <span class="keywordflow">else</span> {
<a name="l04199"></a>04199                                 ys = yp;
<a name="l04200"></a>04200                                 yp++;
<a name="l04201"></a>04201                                 d -= s + a2;
<a name="l04202"></a>04202                                 s += ds;
<a name="l04203"></a>04203                         }
<a name="l04204"></a>04204                 } <span class="keywordflow">else</span> {
<a name="l04205"></a>04205                         yp++;
<a name="l04206"></a>04206                         ys = yp + 1;
<a name="l04207"></a>04207                         d -= s + a2;
<a name="l04208"></a>04208                         s += ds;
<a name="l04209"></a>04209                 }
<a name="l04210"></a>04210 
<a name="l04211"></a>04211                 t -= dt;
<a name="l04212"></a>04212 
<a name="l04213"></a>04213                 <span class="comment">/* Calculate alpha */</span>
<a name="l04214"></a>04214                 <span class="keywordflow">if</span> (s != 0) {
<a name="l04215"></a>04215                         cp = (float) abs(d) / (float) abs(s);
<a name="l04216"></a>04216                         <span class="keywordflow">if</span> (cp &gt; 1.0) {
<a name="l04217"></a>04217                                 cp = 1.0;
<a name="l04218"></a>04218                         }
<a name="l04219"></a>04219                 } <span class="keywordflow">else</span> {
<a name="l04220"></a>04220                         cp = 1.0;
<a name="l04221"></a>04221                 }
<a name="l04222"></a>04222 
<a name="l04223"></a>04223                 <span class="comment">/* Calculate weights */</span>
<a name="l04224"></a>04224                 weight = (Uint8) (cp * 255);
<a name="l04225"></a>04225                 iweight = 255 - weight;
<a name="l04226"></a>04226 
<a name="l04227"></a>04227                 <span class="comment">/* Upper half */</span>
<a name="l04228"></a>04228                 xx = xc2 - xp;
<a name="l04229"></a>04229                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a93c580afe80682f06ef4f1655180aff1" title="Pixel draw with blending enabled and using alpha weight on color - no locking.">pixelColorWeightNolock</a>(dst, xp, yp, color, iweight);
<a name="l04230"></a>04230                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a93c580afe80682f06ef4f1655180aff1" title="Pixel draw with blending enabled and using alpha weight on color - no locking.">pixelColorWeightNolock</a>(dst, xx, yp, color, iweight);
<a name="l04231"></a>04231 
<a name="l04232"></a>04232                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a93c580afe80682f06ef4f1655180aff1" title="Pixel draw with blending enabled and using alpha weight on color - no locking.">pixelColorWeightNolock</a>(dst, xp, ys, color, weight);
<a name="l04233"></a>04233                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a93c580afe80682f06ef4f1655180aff1" title="Pixel draw with blending enabled and using alpha weight on color - no locking.">pixelColorWeightNolock</a>(dst, xx, ys, color, weight);
<a name="l04234"></a>04234 
<a name="l04235"></a>04235                 <span class="comment">/* Lower half */</span>
<a name="l04236"></a>04236                 yy = yc2 - yp;
<a name="l04237"></a>04237                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a93c580afe80682f06ef4f1655180aff1" title="Pixel draw with blending enabled and using alpha weight on color - no locking.">pixelColorWeightNolock</a>(dst, xp, yy, color, iweight);
<a name="l04238"></a>04238                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a93c580afe80682f06ef4f1655180aff1" title="Pixel draw with blending enabled and using alpha weight on color - no locking.">pixelColorWeightNolock</a>(dst, xx, yy, color, iweight);
<a name="l04239"></a>04239 
<a name="l04240"></a>04240                 yy = yc2 - ys;
<a name="l04241"></a>04241                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a93c580afe80682f06ef4f1655180aff1" title="Pixel draw with blending enabled and using alpha weight on color - no locking.">pixelColorWeightNolock</a>(dst, xp, yy, color, weight);
<a name="l04242"></a>04242                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a93c580afe80682f06ef4f1655180aff1" title="Pixel draw with blending enabled and using alpha weight on color - no locking.">pixelColorWeightNolock</a>(dst, xx, yy, color, weight);
<a name="l04243"></a>04243         }
<a name="l04244"></a>04244 
<a name="l04245"></a>04245         <span class="comment">/* Replaces original approximation code dyt = abs(yp - yc); */</span>
<a name="l04246"></a>04246         dyt = (Sint16)lrint((<span class="keywordtype">double</span>)b2 / sab ) + od;    
<a name="l04247"></a>04247 
<a name="l04248"></a>04248         <span class="keywordflow">for</span> (i = 1; i &lt;= dyt; i++) {
<a name="l04249"></a>04249                 yp++;
<a name="l04250"></a>04250                 d -= s + a2;
<a name="l04251"></a>04251 
<a name="l04252"></a>04252                 <span class="keywordflow">if</span> (d &lt;= 0)
<a name="l04253"></a>04253                         xs = xp + 1;
<a name="l04254"></a>04254                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((d + t - b2) &lt; 0) {
<a name="l04255"></a>04255                         <span class="keywordflow">if</span> ((2 * d + t - b2) &lt;= 0)
<a name="l04256"></a>04256                                 xs = xp - 1;
<a name="l04257"></a>04257                         <span class="keywordflow">else</span> {
<a name="l04258"></a>04258                                 xs = xp;
<a name="l04259"></a>04259                                 xp--;
<a name="l04260"></a>04260                                 d += t - b2;
<a name="l04261"></a>04261                                 t -= dt;
<a name="l04262"></a>04262                         }
<a name="l04263"></a>04263                 } <span class="keywordflow">else</span> {
<a name="l04264"></a>04264                         xp--;
<a name="l04265"></a>04265                         xs = xp - 1;
<a name="l04266"></a>04266                         d += t - b2;
<a name="l04267"></a>04267                         t -= dt;
<a name="l04268"></a>04268                 }
<a name="l04269"></a>04269 
<a name="l04270"></a>04270                 s += ds;
<a name="l04271"></a>04271 
<a name="l04272"></a>04272                 <span class="comment">/* Calculate alpha */</span>
<a name="l04273"></a>04273                 <span class="keywordflow">if</span> (t != 0) {
<a name="l04274"></a>04274                         cp = (float) abs(d) / (float) abs(t);
<a name="l04275"></a>04275                         <span class="keywordflow">if</span> (cp &gt; 1.0) {
<a name="l04276"></a>04276                                 cp = 1.0;
<a name="l04277"></a>04277                         }
<a name="l04278"></a>04278                 } <span class="keywordflow">else</span> {
<a name="l04279"></a>04279                         cp = 1.0;
<a name="l04280"></a>04280                 }
<a name="l04281"></a>04281 
<a name="l04282"></a>04282                 <span class="comment">/* Calculate weight */</span>
<a name="l04283"></a>04283                 weight = (Uint8) (cp * 255);
<a name="l04284"></a>04284                 iweight = 255 - weight;
<a name="l04285"></a>04285 
<a name="l04286"></a>04286                 <span class="comment">/* Left half */</span>
<a name="l04287"></a>04287                 xx = xc2 - xp;
<a name="l04288"></a>04288                 yy = yc2 - yp;
<a name="l04289"></a>04289                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a93c580afe80682f06ef4f1655180aff1" title="Pixel draw with blending enabled and using alpha weight on color - no locking.">pixelColorWeightNolock</a>(dst, xp, yp, color, iweight);
<a name="l04290"></a>04290                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a93c580afe80682f06ef4f1655180aff1" title="Pixel draw with blending enabled and using alpha weight on color - no locking.">pixelColorWeightNolock</a>(dst, xx, yp, color, iweight);
<a name="l04291"></a>04291 
<a name="l04292"></a>04292                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a93c580afe80682f06ef4f1655180aff1" title="Pixel draw with blending enabled and using alpha weight on color - no locking.">pixelColorWeightNolock</a>(dst, xp, yy, color, iweight);
<a name="l04293"></a>04293                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a93c580afe80682f06ef4f1655180aff1" title="Pixel draw with blending enabled and using alpha weight on color - no locking.">pixelColorWeightNolock</a>(dst, xx, yy, color, iweight);
<a name="l04294"></a>04294 
<a name="l04295"></a>04295                 <span class="comment">/* Right half */</span>
<a name="l04296"></a>04296                 xx = xc2 - xs;
<a name="l04297"></a>04297                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a93c580afe80682f06ef4f1655180aff1" title="Pixel draw with blending enabled and using alpha weight on color - no locking.">pixelColorWeightNolock</a>(dst, xs, yp, color, weight);
<a name="l04298"></a>04298                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a93c580afe80682f06ef4f1655180aff1" title="Pixel draw with blending enabled and using alpha weight on color - no locking.">pixelColorWeightNolock</a>(dst, xx, yp, color, weight);
<a name="l04299"></a>04299 
<a name="l04300"></a>04300                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a93c580afe80682f06ef4f1655180aff1" title="Pixel draw with blending enabled and using alpha weight on color - no locking.">pixelColorWeightNolock</a>(dst, xs, yy, color, weight);
<a name="l04301"></a>04301                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a93c580afe80682f06ef4f1655180aff1" title="Pixel draw with blending enabled and using alpha weight on color - no locking.">pixelColorWeightNolock</a>(dst, xx, yy, color, weight);
<a name="l04302"></a>04302 
<a name="l04303"></a>04303         }
<a name="l04304"></a>04304 
<a name="l04305"></a>04305         <span class="comment">/* Unlock surface */</span>
<a name="l04306"></a>04306         <span class="keywordflow">if</span> (SDL_MUSTLOCK(dst)) {
<a name="l04307"></a>04307                 SDL_UnlockSurface(dst);
<a name="l04308"></a>04308         }
<a name="l04309"></a>04309 
<a name="l04310"></a>04310         <span class="keywordflow">return</span> (result);
<a name="l04311"></a>04311 }
<a name="l04312"></a>04312 
<a name="l04328"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#ab6db169d39ea972469e761f338153e21">04328</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#ab9f0f00d7fb2f04aa9ba1630e31a27bf" title="Draw anti-aliased ellipse with blending.">aaellipseRGBA</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l04329"></a>04329 {
<a name="l04330"></a>04330         <span class="comment">/*</span>
<a name="l04331"></a>04331 <span class="comment">        * Draw </span>
<a name="l04332"></a>04332 <span class="comment">        */</span>
<a name="l04333"></a>04333         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a1c7d20dcba8e0d7ce483f4c854c438be" title="Draw anti-aliased ellipse with blending.">aaellipseColor</a>
<a name="l04334"></a>04334                 (dst, x, y, rx, ry, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a));
<a name="l04335"></a>04335 }
<a name="l04336"></a>04336 
<a name="l04337"></a>04337 <span class="comment">/* ---- Filled Ellipse */</span>
<a name="l04338"></a>04338 
<a name="l04339"></a>04339 <span class="comment">/* Note: */</span>
<a name="l04340"></a>04340 <span class="comment">/* Based on algorithm from sge library with multiple-hline draw removal */</span>
<a name="l04341"></a>04341 <span class="comment">/* and other speedup changes. */</span>
<a name="l04342"></a>04342 
<a name="l04358"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a36e83e5648b95d38d1efe98dcf840fab">04358</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a8fed50800f2f1bdfaa048698f5052f25" title="Draw filled ellipse with blending.">filledEllipseColor</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color)
<a name="l04359"></a>04359 {
<a name="l04360"></a>04360         Sint16 left, right, top, bottom;
<a name="l04361"></a>04361         <span class="keywordtype">int</span> result;
<a name="l04362"></a>04362         Sint16 x1, y1, x2, y2;
<a name="l04363"></a>04363         <span class="keywordtype">int</span> ix, iy;
<a name="l04364"></a>04364         <span class="keywordtype">int</span> h, i, j, k;
<a name="l04365"></a>04365         <span class="keywordtype">int</span> oh, oi, oj, ok;
<a name="l04366"></a>04366         <span class="keywordtype">int</span> xmh, xph;
<a name="l04367"></a>04367         <span class="keywordtype">int</span> xmi, xpi;
<a name="l04368"></a>04368         <span class="keywordtype">int</span> xmj, xpj;
<a name="l04369"></a>04369         <span class="keywordtype">int</span> xmk, xpk;
<a name="l04370"></a>04370 
<a name="l04371"></a>04371         <span class="comment">/*</span>
<a name="l04372"></a>04372 <span class="comment">        * Check visibility of clipping rectangle</span>
<a name="l04373"></a>04373 <span class="comment">        */</span>
<a name="l04374"></a>04374         <span class="keywordflow">if</span> ((dst-&gt;clip_rect.w==0) || (dst-&gt;clip_rect.h==0)) {
<a name="l04375"></a>04375                 <span class="keywordflow">return</span>(0);
<a name="l04376"></a>04376         }
<a name="l04377"></a>04377 
<a name="l04378"></a>04378         <span class="comment">/*</span>
<a name="l04379"></a>04379 <span class="comment">        * Sanity check radii </span>
<a name="l04380"></a>04380 <span class="comment">        */</span>
<a name="l04381"></a>04381         <span class="keywordflow">if</span> ((rx &lt; 0) || (ry &lt; 0)) {
<a name="l04382"></a>04382                 <span class="keywordflow">return</span> (-1);
<a name="l04383"></a>04383         }
<a name="l04384"></a>04384 
<a name="l04385"></a>04385         <span class="comment">/*</span>
<a name="l04386"></a>04386 <span class="comment">        * Special case for rx=0 - draw a vline </span>
<a name="l04387"></a>04387 <span class="comment">        */</span>
<a name="l04388"></a>04388         <span class="keywordflow">if</span> (rx == 0) {
<a name="l04389"></a>04389                 <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a9b45060155a19fee24f998d7790f1d67" title="Draw vertical line with blending.">vlineColor</a>(dst, x, y - ry, y + ry, color));
<a name="l04390"></a>04390         }
<a name="l04391"></a>04391         <span class="comment">/*</span>
<a name="l04392"></a>04392 <span class="comment">        * Special case for ry=0 - draw a hline </span>
<a name="l04393"></a>04393 <span class="comment">        */</span>
<a name="l04394"></a>04394         <span class="keywordflow">if</span> (ry == 0) {
<a name="l04395"></a>04395                 <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, x - rx, x + rx, y, color));
<a name="l04396"></a>04396         }
<a name="l04397"></a>04397 
<a name="l04398"></a>04398         <span class="comment">/*</span>
<a name="l04399"></a>04399 <span class="comment">        * Get circle and clipping boundary and </span>
<a name="l04400"></a>04400 <span class="comment">        * test if bounding box of circle is visible </span>
<a name="l04401"></a>04401 <span class="comment">        */</span>
<a name="l04402"></a>04402         x2 = x + rx;
<a name="l04403"></a>04403         left = dst-&gt;clip_rect.x;
<a name="l04404"></a>04404         <span class="keywordflow">if</span> (x2&lt;left) {
<a name="l04405"></a>04405                 <span class="keywordflow">return</span>(0);
<a name="l04406"></a>04406         } 
<a name="l04407"></a>04407         x1 = x - rx;
<a name="l04408"></a>04408         right = dst-&gt;clip_rect.x + dst-&gt;clip_rect.w - 1;
<a name="l04409"></a>04409         <span class="keywordflow">if</span> (x1&gt;right) {
<a name="l04410"></a>04410                 <span class="keywordflow">return</span>(0);
<a name="l04411"></a>04411         } 
<a name="l04412"></a>04412         y2 = y + ry;
<a name="l04413"></a>04413         top = dst-&gt;clip_rect.y;
<a name="l04414"></a>04414         <span class="keywordflow">if</span> (y2&lt;top) {
<a name="l04415"></a>04415                 <span class="keywordflow">return</span>(0);
<a name="l04416"></a>04416         } 
<a name="l04417"></a>04417         y1 = y - ry;
<a name="l04418"></a>04418         bottom = dst-&gt;clip_rect.y + dst-&gt;clip_rect.h - 1;
<a name="l04419"></a>04419         <span class="keywordflow">if</span> (y1&gt;bottom) {
<a name="l04420"></a>04420                 <span class="keywordflow">return</span>(0);
<a name="l04421"></a>04421         } 
<a name="l04422"></a>04422 
<a name="l04423"></a>04423         <span class="comment">/*</span>
<a name="l04424"></a>04424 <span class="comment">        * Init vars </span>
<a name="l04425"></a>04425 <span class="comment">        */</span>
<a name="l04426"></a>04426         oh = oi = oj = ok = 0xFFFF;
<a name="l04427"></a>04427 
<a name="l04428"></a>04428         <span class="comment">/*</span>
<a name="l04429"></a>04429 <span class="comment">        * Draw </span>
<a name="l04430"></a>04430 <span class="comment">        */</span>
<a name="l04431"></a>04431         result = 0;
<a name="l04432"></a>04432         <span class="keywordflow">if</span> (rx &gt; ry) {
<a name="l04433"></a>04433                 ix = 0;
<a name="l04434"></a>04434                 iy = rx * 64;
<a name="l04435"></a>04435 
<a name="l04436"></a>04436                 <span class="keywordflow">do</span> {
<a name="l04437"></a>04437                         h = (ix + 32) &gt;&gt; 6;
<a name="l04438"></a>04438                         i = (iy + 32) &gt;&gt; 6;
<a name="l04439"></a>04439                         j = (h * ry) / rx;
<a name="l04440"></a>04440                         k = (i * ry) / rx;
<a name="l04441"></a>04441 
<a name="l04442"></a>04442                         <span class="keywordflow">if</span> ((ok != k) &amp;&amp; (oj != k)) {
<a name="l04443"></a>04443                                 xph = x + h;
<a name="l04444"></a>04444                                 xmh = x - h;
<a name="l04445"></a>04445                                 <span class="keywordflow">if</span> (k &gt; 0) {
<a name="l04446"></a>04446                                         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, xmh, xph, y + k, color);
<a name="l04447"></a>04447                                         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, xmh, xph, y - k, color);
<a name="l04448"></a>04448                                 } <span class="keywordflow">else</span> {
<a name="l04449"></a>04449                                         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, xmh, xph, y, color);
<a name="l04450"></a>04450                                 }
<a name="l04451"></a>04451                                 ok = k;
<a name="l04452"></a>04452                         }
<a name="l04453"></a>04453                         <span class="keywordflow">if</span> ((oj != j) &amp;&amp; (ok != j) &amp;&amp; (k != j)) {
<a name="l04454"></a>04454                                 xmi = x - i;
<a name="l04455"></a>04455                                 xpi = x + i;
<a name="l04456"></a>04456                                 <span class="keywordflow">if</span> (j &gt; 0) {
<a name="l04457"></a>04457                                         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, xmi, xpi, y + j, color);
<a name="l04458"></a>04458                                         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, xmi, xpi, y - j, color);
<a name="l04459"></a>04459                                 } <span class="keywordflow">else</span> {
<a name="l04460"></a>04460                                         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, xmi, xpi, y, color);
<a name="l04461"></a>04461                                 }
<a name="l04462"></a>04462                                 oj = j;
<a name="l04463"></a>04463                         }
<a name="l04464"></a>04464 
<a name="l04465"></a>04465                         ix = ix + iy / rx;
<a name="l04466"></a>04466                         iy = iy - ix / rx;
<a name="l04467"></a>04467 
<a name="l04468"></a>04468                 } <span class="keywordflow">while</span> (i &gt; h);
<a name="l04469"></a>04469         } <span class="keywordflow">else</span> {
<a name="l04470"></a>04470                 ix = 0;
<a name="l04471"></a>04471                 iy = ry * 64;
<a name="l04472"></a>04472 
<a name="l04473"></a>04473                 <span class="keywordflow">do</span> {
<a name="l04474"></a>04474                         h = (ix + 32) &gt;&gt; 6;
<a name="l04475"></a>04475                         i = (iy + 32) &gt;&gt; 6;
<a name="l04476"></a>04476                         j = (h * rx) / ry;
<a name="l04477"></a>04477                         k = (i * rx) / ry;
<a name="l04478"></a>04478 
<a name="l04479"></a>04479                         <span class="keywordflow">if</span> ((oi != i) &amp;&amp; (oh != i)) {
<a name="l04480"></a>04480                                 xmj = x - j;
<a name="l04481"></a>04481                                 xpj = x + j;
<a name="l04482"></a>04482                                 <span class="keywordflow">if</span> (i &gt; 0) {
<a name="l04483"></a>04483                                         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, xmj, xpj, y + i, color);
<a name="l04484"></a>04484                                         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, xmj, xpj, y - i, color);
<a name="l04485"></a>04485                                 } <span class="keywordflow">else</span> {
<a name="l04486"></a>04486                                         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, xmj, xpj, y, color);
<a name="l04487"></a>04487                                 }
<a name="l04488"></a>04488                                 oi = i;
<a name="l04489"></a>04489                         }
<a name="l04490"></a>04490                         <span class="keywordflow">if</span> ((oh != h) &amp;&amp; (oi != h) &amp;&amp; (i != h)) {
<a name="l04491"></a>04491                                 xmk = x - k;
<a name="l04492"></a>04492                                 xpk = x + k;
<a name="l04493"></a>04493                                 <span class="keywordflow">if</span> (h &gt; 0) {
<a name="l04494"></a>04494                                         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, xmk, xpk, y + h, color);
<a name="l04495"></a>04495                                         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, xmk, xpk, y - h, color);
<a name="l04496"></a>04496                                 } <span class="keywordflow">else</span> {
<a name="l04497"></a>04497                                         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, xmk, xpk, y, color);
<a name="l04498"></a>04498                                 }
<a name="l04499"></a>04499                                 oh = h;
<a name="l04500"></a>04500                         }
<a name="l04501"></a>04501 
<a name="l04502"></a>04502                         ix = ix + iy / ry;
<a name="l04503"></a>04503                         iy = iy - ix / ry;
<a name="l04504"></a>04504 
<a name="l04505"></a>04505                 } <span class="keywordflow">while</span> (i &gt; h);
<a name="l04506"></a>04506         }
<a name="l04507"></a>04507 
<a name="l04508"></a>04508         <span class="keywordflow">return</span> (result);
<a name="l04509"></a>04509 }
<a name="l04510"></a>04510 
<a name="l04526"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a26f01b9c0cf7a533023869dff439254f">04526</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a33595ad996dd0dcccde3abbcef540eec" title="Draw filled ellipse with blending.">filledEllipseRGBA</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l04527"></a>04527 {
<a name="l04528"></a>04528         <span class="comment">/*</span>
<a name="l04529"></a>04529 <span class="comment">        * Draw </span>
<a name="l04530"></a>04530 <span class="comment">        */</span>
<a name="l04531"></a>04531         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a8fed50800f2f1bdfaa048698f5052f25" title="Draw filled ellipse with blending.">filledEllipseColor</a>
<a name="l04532"></a>04532                 (dst, x, y, rx, ry, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a));
<a name="l04533"></a>04533 }
<a name="l04534"></a>04534 
<a name="l04535"></a>04535 <span class="comment">/* ----- pie */</span>
<a name="l04536"></a>04536 
<a name="l04553"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#ac2e0cefca34b74c900cfa68e3915487b">04553</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac2e0cefca34b74c900cfa68e3915487b" title="Internal float (low-speed) pie-calc implementation by drawing polygons.">_pieColor</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad, Sint16 start, Sint16 end, Uint32 color, Uint8 filled)
<a name="l04554"></a>04554 {
<a name="l04555"></a>04555         Sint16 left, right, top, bottom;
<a name="l04556"></a>04556         Sint16 x1, y1, x2, y2;
<a name="l04557"></a>04557         <span class="keywordtype">int</span> result;
<a name="l04558"></a>04558         <span class="keywordtype">double</span> angle, start_angle, end_angle;
<a name="l04559"></a>04559         <span class="keywordtype">double</span> deltaAngle;
<a name="l04560"></a>04560         <span class="keywordtype">double</span> dr;
<a name="l04561"></a>04561         <span class="keywordtype">int</span> numpoints, i;
<a name="l04562"></a>04562         Sint16 *vx, *vy;
<a name="l04563"></a>04563 
<a name="l04564"></a>04564         <span class="comment">/*</span>
<a name="l04565"></a>04565 <span class="comment">        * Check visibility of clipping rectangle</span>
<a name="l04566"></a>04566 <span class="comment">        */</span>
<a name="l04567"></a>04567         <span class="keywordflow">if</span> ((dst-&gt;clip_rect.w==0) || (dst-&gt;clip_rect.h==0)) {
<a name="l04568"></a>04568                 <span class="keywordflow">return</span>(0);
<a name="l04569"></a>04569         }
<a name="l04570"></a>04570 
<a name="l04571"></a>04571         <span class="comment">/*</span>
<a name="l04572"></a>04572 <span class="comment">        * Sanity check radii </span>
<a name="l04573"></a>04573 <span class="comment">        */</span>
<a name="l04574"></a>04574         <span class="keywordflow">if</span> (rad &lt; 0) {
<a name="l04575"></a>04575                 <span class="keywordflow">return</span> (-1);
<a name="l04576"></a>04576         }
<a name="l04577"></a>04577 
<a name="l04578"></a>04578         <span class="comment">/*</span>
<a name="l04579"></a>04579 <span class="comment">        * Fixup angles</span>
<a name="l04580"></a>04580 <span class="comment">        */</span>
<a name="l04581"></a>04581         start = start % 360;
<a name="l04582"></a>04582         end = end % 360;
<a name="l04583"></a>04583 
<a name="l04584"></a>04584         <span class="comment">/*</span>
<a name="l04585"></a>04585 <span class="comment">        * Special case for rad=0 - draw a point </span>
<a name="l04586"></a>04586 <span class="comment">        */</span>
<a name="l04587"></a>04587         <span class="keywordflow">if</span> (rad == 0) {
<a name="l04588"></a>04588                 <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ae6f8690e5c5a85d3263c8e16727b34ef" title="Pixel draw with blending enabled if a&lt;255.">pixelColor</a>(dst, x, y, color));
<a name="l04589"></a>04589         }
<a name="l04590"></a>04590 
<a name="l04591"></a>04591         <span class="comment">/*</span>
<a name="l04592"></a>04592 <span class="comment">        * Clip against circle, not pie (not 100% optimal).</span>
<a name="l04593"></a>04593 <span class="comment">        * Get pie&#39;s circle and clipping boundary and </span>
<a name="l04594"></a>04594 <span class="comment">        * test if bounding box of circle is visible</span>
<a name="l04595"></a>04595 <span class="comment">        */</span>
<a name="l04596"></a>04596         x2 = x + rad;
<a name="l04597"></a>04597         left = dst-&gt;clip_rect.x;
<a name="l04598"></a>04598         <span class="keywordflow">if</span> (x2&lt;left) {
<a name="l04599"></a>04599                 <span class="keywordflow">return</span>(0);
<a name="l04600"></a>04600         } 
<a name="l04601"></a>04601         x1 = x - rad;
<a name="l04602"></a>04602         right = dst-&gt;clip_rect.x + dst-&gt;clip_rect.w - 1;
<a name="l04603"></a>04603         <span class="keywordflow">if</span> (x1&gt;right) {
<a name="l04604"></a>04604                 <span class="keywordflow">return</span>(0);
<a name="l04605"></a>04605         } 
<a name="l04606"></a>04606         y2 = y + rad;
<a name="l04607"></a>04607         top = dst-&gt;clip_rect.y;
<a name="l04608"></a>04608         <span class="keywordflow">if</span> (y2&lt;top) {
<a name="l04609"></a>04609                 <span class="keywordflow">return</span>(0);
<a name="l04610"></a>04610         } 
<a name="l04611"></a>04611         y1 = y - rad;
<a name="l04612"></a>04612         bottom = dst-&gt;clip_rect.y + dst-&gt;clip_rect.h - 1;
<a name="l04613"></a>04613         <span class="keywordflow">if</span> (y1&gt;bottom) {
<a name="l04614"></a>04614                 <span class="keywordflow">return</span>(0);
<a name="l04615"></a>04615         } 
<a name="l04616"></a>04616 
<a name="l04617"></a>04617         <span class="comment">/*</span>
<a name="l04618"></a>04618 <span class="comment">        * Variable setup </span>
<a name="l04619"></a>04619 <span class="comment">        */</span>
<a name="l04620"></a>04620         dr = (double) rad;
<a name="l04621"></a>04621         deltaAngle = 3.0 / dr;
<a name="l04622"></a>04622         start_angle = (double) start *(2.0 * <a class="code" href="_s_d_l__gfx_primitives_8h.html#ae71449b1cc6e6250b91f539153a7a0d3">M_PI</a> / 360.0);
<a name="l04623"></a>04623         end_angle = (double) end *(2.0 * <a class="code" href="_s_d_l__gfx_primitives_8h.html#ae71449b1cc6e6250b91f539153a7a0d3">M_PI</a> / 360.0);
<a name="l04624"></a>04624         <span class="keywordflow">if</span> (start &gt; end) {
<a name="l04625"></a>04625                 end_angle += (2.0 * <a class="code" href="_s_d_l__gfx_primitives_8h.html#ae71449b1cc6e6250b91f539153a7a0d3">M_PI</a>);
<a name="l04626"></a>04626         }
<a name="l04627"></a>04627 
<a name="l04628"></a>04628         <span class="comment">/* We will always have at least 2 points */</span>
<a name="l04629"></a>04629         numpoints = 2;
<a name="l04630"></a>04630 
<a name="l04631"></a>04631         <span class="comment">/* Count points (rather than calculating it) */</span>
<a name="l04632"></a>04632         angle = start_angle;
<a name="l04633"></a>04633         <span class="keywordflow">while</span> (angle &lt; end_angle) {
<a name="l04634"></a>04634                 angle += deltaAngle;
<a name="l04635"></a>04635                 numpoints++;
<a name="l04636"></a>04636         }
<a name="l04637"></a>04637 
<a name="l04638"></a>04638         <span class="comment">/* Allocate combined vertex array */</span>
<a name="l04639"></a>04639         vx = vy = (Sint16 *) malloc(2 * <span class="keyword">sizeof</span>(Uint16) * numpoints);
<a name="l04640"></a>04640         <span class="keywordflow">if</span> (vx == NULL) {
<a name="l04641"></a>04641                 <span class="keywordflow">return</span> (-1);
<a name="l04642"></a>04642         }
<a name="l04643"></a>04643 
<a name="l04644"></a>04644         <span class="comment">/* Update point to start of vy */</span>
<a name="l04645"></a>04645         vy += numpoints;
<a name="l04646"></a>04646 
<a name="l04647"></a>04647         <span class="comment">/* Center */</span>
<a name="l04648"></a>04648         vx[0] = x;
<a name="l04649"></a>04649         vy[0] = y;
<a name="l04650"></a>04650 
<a name="l04651"></a>04651         <span class="comment">/* First vertex */</span>
<a name="l04652"></a>04652         angle = start_angle;
<a name="l04653"></a>04653         vx[1] = x + (int) (dr * cos(angle));
<a name="l04654"></a>04654         vy[1] = y + (int) (dr * sin(angle));
<a name="l04655"></a>04655 
<a name="l04656"></a>04656         <span class="keywordflow">if</span> (numpoints&lt;3)
<a name="l04657"></a>04657         {
<a name="l04658"></a>04658                 result = <a class="code" href="_s_d_l__gfx_primitives_8c.html#ad44c550fab3cb736eb049713ede94052" title="Draw line with alpha blending.">lineColor</a>(dst, vx[0], vy[0], vx[1], vy[1], color);
<a name="l04659"></a>04659         }
<a name="l04660"></a>04660         <span class="keywordflow">else</span>
<a name="l04661"></a>04661         {
<a name="l04662"></a>04662                 <span class="comment">/* Calculate other vertices */</span>
<a name="l04663"></a>04663                 i = 2;
<a name="l04664"></a>04664                 angle = start_angle;
<a name="l04665"></a>04665                 <span class="keywordflow">while</span> (angle &lt; end_angle) {
<a name="l04666"></a>04666                         angle += deltaAngle;
<a name="l04667"></a>04667                         <span class="keywordflow">if</span> (angle&gt;end_angle)
<a name="l04668"></a>04668                         {
<a name="l04669"></a>04669                                 angle = end_angle;
<a name="l04670"></a>04670                         }
<a name="l04671"></a>04671                         vx[i] = x + (int) (dr * cos(angle));
<a name="l04672"></a>04672                         vy[i] = y + (int) (dr * sin(angle));
<a name="l04673"></a>04673                         i++;
<a name="l04674"></a>04674                 }
<a name="l04675"></a>04675 
<a name="l04676"></a>04676                 <span class="comment">/* Draw */</span>
<a name="l04677"></a>04677                 <span class="keywordflow">if</span> (filled) {
<a name="l04678"></a>04678                         result = <a class="code" href="_s_d_l__gfx_primitives_8c.html#af22692175cb73329410cbcc7d7491c4d" title="Draw filled polygon with alpha blending.">filledPolygonColor</a>(dst, vx, vy, numpoints, color);
<a name="l04679"></a>04679                 } <span class="keywordflow">else</span> {
<a name="l04680"></a>04680                         result = <a class="code" href="_s_d_l__gfx_primitives_8c.html#a2d692dc25f3b579b386dff8dcd9cbc00" title="Draw polygon with alpha blending.">polygonColor</a>(dst, vx, vy, numpoints, color);
<a name="l04681"></a>04681                 }
<a name="l04682"></a>04682         }
<a name="l04683"></a>04683 
<a name="l04684"></a>04684         <span class="comment">/* Free combined vertex array */</span>
<a name="l04685"></a>04685         free(vx);
<a name="l04686"></a>04686 
<a name="l04687"></a>04687         <span class="keywordflow">return</span> (result);
<a name="l04688"></a>04688 }
<a name="l04689"></a>04689 
<a name="l04703"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a6476d5dad22631d10c1dc95b0e88fc65">04703</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a3c2bc64deabda74933f31daba6bed7be" title="Draw pie (outline) with alpha blending.">pieColor</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad, 
<a name="l04704"></a>04704         Sint16 start, Sint16 end, Uint32 color) 
<a name="l04705"></a>04705 {
<a name="l04706"></a>04706         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ac2e0cefca34b74c900cfa68e3915487b" title="Internal float (low-speed) pie-calc implementation by drawing polygons.">_pieColor</a>(dst, x, y, rad, start, end, color, 0));
<a name="l04707"></a>04707 
<a name="l04708"></a>04708 }
<a name="l04709"></a>04709 
<a name="l04726"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a4a5e4344913667e714560dd204473663">04726</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a8442f2c2bedbe27c96d8d44319981992" title="Draw pie (outline) with alpha blending.">pieRGBA</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad,
<a name="l04727"></a>04727         Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l04728"></a>04728 {
<a name="l04729"></a>04729         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ac2e0cefca34b74c900cfa68e3915487b" title="Internal float (low-speed) pie-calc implementation by drawing polygons.">_pieColor</a>(dst, x, y, rad, start, end,
<a name="l04730"></a>04730                 ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a, 0));
<a name="l04731"></a>04731 
<a name="l04732"></a>04732 }
<a name="l04733"></a>04733 
<a name="l04747"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a8f18679aa7161f885613ec08e7f41692">04747</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a2c30ee985b2513dc58d9b19d4e71562b" title="Draw filled pie with alpha blending.">filledPieColor</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad, Sint16 start, Sint16 end, Uint32 color)
<a name="l04748"></a>04748 {
<a name="l04749"></a>04749         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ac2e0cefca34b74c900cfa68e3915487b" title="Internal float (low-speed) pie-calc implementation by drawing polygons.">_pieColor</a>(dst, x, y, rad, start, end, color, 1));
<a name="l04750"></a>04750 }
<a name="l04751"></a>04751 
<a name="l04768"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a1944c066d27fa9847a5fdecd1d3b9116">04768</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a4ffdfd2834f3ef0fd0ee622b5f1d16b8" title="Draw filled pie with alpha blending.">filledPieRGBA</a>(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad,
<a name="l04769"></a>04769         Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l04770"></a>04770 {
<a name="l04771"></a>04771         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#ac2e0cefca34b74c900cfa68e3915487b" title="Internal float (low-speed) pie-calc implementation by drawing polygons.">_pieColor</a>(dst, x, y, rad, start, end,
<a name="l04772"></a>04772                 ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a, 1));
<a name="l04773"></a>04773 }
<a name="l04774"></a>04774 
<a name="l04775"></a>04775 <span class="comment">/* ------ Trigon */</span>
<a name="l04776"></a>04776 
<a name="l04793"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#aec2a0c435b879a29167be6b1c49f1e49">04793</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a7465d08ef930ebb5442c7dd246fed4b5" title="Draw trigon (triangle outline) with alpha blending.">trigonColor</a>(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color)
<a name="l04794"></a>04794 {
<a name="l04795"></a>04795         Sint16 vx[3]; 
<a name="l04796"></a>04796         Sint16 vy[3];
<a name="l04797"></a>04797 
<a name="l04798"></a>04798         vx[0]=x1;
<a name="l04799"></a>04799         vx[1]=x2;
<a name="l04800"></a>04800         vx[2]=x3;
<a name="l04801"></a>04801         vy[0]=y1;
<a name="l04802"></a>04802         vy[1]=y2;
<a name="l04803"></a>04803         vy[2]=y3;
<a name="l04804"></a>04804 
<a name="l04805"></a>04805         <span class="keywordflow">return</span>(<a class="code" href="_s_d_l__gfx_primitives_8c.html#a2d692dc25f3b579b386dff8dcd9cbc00" title="Draw polygon with alpha blending.">polygonColor</a>(dst,vx,vy,3,color));
<a name="l04806"></a>04806 }
<a name="l04807"></a>04807 
<a name="l04825"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a090024f5f3e38b02b0bca704259b9d11">04825</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a45d6a7edcd8b25e1a60e39b7f60bda3f" title="Draw trigon (triangle outline) with alpha blending.">trigonRGBA</a>(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
<a name="l04826"></a>04826         Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l04827"></a>04827 {
<a name="l04828"></a>04828         Sint16 vx[3]; 
<a name="l04829"></a>04829         Sint16 vy[3];
<a name="l04830"></a>04830 
<a name="l04831"></a>04831         vx[0]=x1;
<a name="l04832"></a>04832         vx[1]=x2;
<a name="l04833"></a>04833         vx[2]=x3;
<a name="l04834"></a>04834         vy[0]=y1;
<a name="l04835"></a>04835         vy[1]=y2;
<a name="l04836"></a>04836         vy[2]=y3;
<a name="l04837"></a>04837 
<a name="l04838"></a>04838         <span class="keywordflow">return</span>(<a class="code" href="_s_d_l__gfx_primitives_8c.html#ae55541ec58990420dc6dc6b9d61f33d6" title="Draw polygon with alpha blending.">polygonRGBA</a>(dst,vx,vy,3,r,g,b,a));
<a name="l04839"></a>04839 }                                
<a name="l04840"></a>04840 
<a name="l04841"></a>04841 <span class="comment">/* ------ AA-Trigon */</span>
<a name="l04842"></a>04842 
<a name="l04859"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a330917705809bb5f7d74ef232dde5f12">04859</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a4f928dfaef530c83e304a452d2e55190" title="Draw anti-aliased trigon (triangle outline) with alpha blending.">aatrigonColor</a>(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color)
<a name="l04860"></a>04860 {
<a name="l04861"></a>04861         Sint16 vx[3]; 
<a name="l04862"></a>04862         Sint16 vy[3];
<a name="l04863"></a>04863 
<a name="l04864"></a>04864         vx[0]=x1;
<a name="l04865"></a>04865         vx[1]=x2;
<a name="l04866"></a>04866         vx[2]=x3;
<a name="l04867"></a>04867         vy[0]=y1;
<a name="l04868"></a>04868         vy[1]=y2;
<a name="l04869"></a>04869         vy[2]=y3;
<a name="l04870"></a>04870 
<a name="l04871"></a>04871         <span class="keywordflow">return</span>(<a class="code" href="_s_d_l__gfx_primitives_8c.html#a09950a50e8806e88bb20c543c58cc6a8" title="Draw anti-aliased polygon with alpha blending.">aapolygonColor</a>(dst,vx,vy,3,color));
<a name="l04872"></a>04872 }
<a name="l04873"></a>04873 
<a name="l04891"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a5e88106c90fc2e0e25d0f7617459d4f9">04891</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#ab53a84faa65b68e40cb68b8cacbb4b7d" title="Draw anti-aliased trigon (triangle outline) with alpha blending.">aatrigonRGBA</a>(SDL_Surface * dst,  Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
<a name="l04892"></a>04892         Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l04893"></a>04893 {
<a name="l04894"></a>04894         Sint16 vx[3]; 
<a name="l04895"></a>04895         Sint16 vy[3];
<a name="l04896"></a>04896 
<a name="l04897"></a>04897         vx[0]=x1;
<a name="l04898"></a>04898         vx[1]=x2;
<a name="l04899"></a>04899         vx[2]=x3;
<a name="l04900"></a>04900         vy[0]=y1;
<a name="l04901"></a>04901         vy[1]=y2;
<a name="l04902"></a>04902         vy[2]=y3;
<a name="l04903"></a>04903 
<a name="l04904"></a>04904         <span class="keywordflow">return</span>(<a class="code" href="_s_d_l__gfx_primitives_8c.html#a7d08522e52d8290c5c498ce435fa51f0" title="Draw anti-aliased polygon with alpha blending.">aapolygonRGBA</a>(dst,vx,vy,3,r,g,b,a));
<a name="l04905"></a>04905 }                                  
<a name="l04906"></a>04906 
<a name="l04907"></a>04907 <span class="comment">/* ------ Filled Trigon */</span>
<a name="l04908"></a>04908 
<a name="l04925"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a6adaf54b33bf067e4fe2cc5a7ae17ef6">04925</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a78d4ed2372527f3b78f5893928b0f519" title="Draw filled trigon (triangle) with alpha blending.">filledTrigonColor</a>(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color)
<a name="l04926"></a>04926 {
<a name="l04927"></a>04927         Sint16 vx[3]; 
<a name="l04928"></a>04928         Sint16 vy[3];
<a name="l04929"></a>04929 
<a name="l04930"></a>04930         vx[0]=x1;
<a name="l04931"></a>04931         vx[1]=x2;
<a name="l04932"></a>04932         vx[2]=x3;
<a name="l04933"></a>04933         vy[0]=y1;
<a name="l04934"></a>04934         vy[1]=y2;
<a name="l04935"></a>04935         vy[2]=y3;
<a name="l04936"></a>04936 
<a name="l04937"></a>04937         <span class="keywordflow">return</span>(<a class="code" href="_s_d_l__gfx_primitives_8c.html#af22692175cb73329410cbcc7d7491c4d" title="Draw filled polygon with alpha blending.">filledPolygonColor</a>(dst,vx,vy,3,color));
<a name="l04938"></a>04938 }
<a name="l04939"></a>04939 
<a name="l04959"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a4a3318a183659aab7c12c0334e261837">04959</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a8f318d776ff1e3c6790405e0e59e5356" title="Draw filled trigon (triangle) with alpha blending.">filledTrigonRGBA</a>(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
<a name="l04960"></a>04960         Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l04961"></a>04961 {
<a name="l04962"></a>04962         Sint16 vx[3]; 
<a name="l04963"></a>04963         Sint16 vy[3];
<a name="l04964"></a>04964 
<a name="l04965"></a>04965         vx[0]=x1;
<a name="l04966"></a>04966         vx[1]=x2;
<a name="l04967"></a>04967         vx[2]=x3;
<a name="l04968"></a>04968         vy[0]=y1;
<a name="l04969"></a>04969         vy[1]=y2;
<a name="l04970"></a>04970         vy[2]=y3;
<a name="l04971"></a>04971 
<a name="l04972"></a>04972         <span class="keywordflow">return</span>(<a class="code" href="_s_d_l__gfx_primitives_8c.html#a40ef0b898905c190c193f0f55deb5a6c" title="Draw filled polygon with alpha blending.">filledPolygonRGBA</a>(dst,vx,vy,3,r,g,b,a));
<a name="l04973"></a>04973 }
<a name="l04974"></a>04974 
<a name="l04975"></a>04975 <span class="comment">/* ---- Polygon */</span>
<a name="l04976"></a>04976 
<a name="l04988"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#abe5d0b2f6193558798eaff3e85e7a1af">04988</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a2d692dc25f3b579b386dff8dcd9cbc00" title="Draw polygon with alpha blending.">polygonColor</a>(SDL_Surface * dst, <span class="keyword">const</span> Sint16 * vx, <span class="keyword">const</span> Sint16 * vy, <span class="keywordtype">int</span> n, Uint32 color)
<a name="l04989"></a>04989 {
<a name="l04990"></a>04990         <span class="keywordtype">int</span> result;
<a name="l04991"></a>04991         <span class="keywordtype">int</span> i;
<a name="l04992"></a>04992         <span class="keyword">const</span> Sint16 *x1, *y1, *x2, *y2;
<a name="l04993"></a>04993 
<a name="l04994"></a>04994         <span class="comment">/*</span>
<a name="l04995"></a>04995 <span class="comment">        * Check visibility of clipping rectangle</span>
<a name="l04996"></a>04996 <span class="comment">        */</span>
<a name="l04997"></a>04997         <span class="keywordflow">if</span> ((dst-&gt;clip_rect.w==0) || (dst-&gt;clip_rect.h==0)) {
<a name="l04998"></a>04998                 <span class="keywordflow">return</span>(0);
<a name="l04999"></a>04999         }
<a name="l05000"></a>05000 
<a name="l05001"></a>05001         <span class="comment">/*</span>
<a name="l05002"></a>05002 <span class="comment">        * Vertex array NULL check </span>
<a name="l05003"></a>05003 <span class="comment">        */</span>
<a name="l05004"></a>05004         <span class="keywordflow">if</span> (vx == NULL) {
<a name="l05005"></a>05005                 <span class="keywordflow">return</span> (-1);
<a name="l05006"></a>05006         }
<a name="l05007"></a>05007         <span class="keywordflow">if</span> (vy == NULL) {
<a name="l05008"></a>05008                 <span class="keywordflow">return</span> (-1);
<a name="l05009"></a>05009         }
<a name="l05010"></a>05010 
<a name="l05011"></a>05011         <span class="comment">/*</span>
<a name="l05012"></a>05012 <span class="comment">        * Sanity check </span>
<a name="l05013"></a>05013 <span class="comment">        */</span>
<a name="l05014"></a>05014         <span class="keywordflow">if</span> (n &lt; 3) {
<a name="l05015"></a>05015                 <span class="keywordflow">return</span> (-1);
<a name="l05016"></a>05016         }
<a name="l05017"></a>05017 
<a name="l05018"></a>05018         <span class="comment">/*</span>
<a name="l05019"></a>05019 <span class="comment">        * Pointer setup </span>
<a name="l05020"></a>05020 <span class="comment">        */</span>
<a name="l05021"></a>05021         x1 = x2 = vx;
<a name="l05022"></a>05022         y1 = y2 = vy;
<a name="l05023"></a>05023         x2++;
<a name="l05024"></a>05024         y2++;
<a name="l05025"></a>05025 
<a name="l05026"></a>05026         <span class="comment">/*</span>
<a name="l05027"></a>05027 <span class="comment">        * Draw </span>
<a name="l05028"></a>05028 <span class="comment">        */</span>
<a name="l05029"></a>05029         result = 0;
<a name="l05030"></a>05030         <span class="keywordflow">for</span> (i = 1; i &lt; n; i++) {
<a name="l05031"></a>05031                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ad44c550fab3cb736eb049713ede94052" title="Draw line with alpha blending.">lineColor</a>(dst, *x1, *y1, *x2, *y2, color);
<a name="l05032"></a>05032                 x1 = x2;
<a name="l05033"></a>05033                 y1 = y2;
<a name="l05034"></a>05034                 x2++;
<a name="l05035"></a>05035                 y2++;
<a name="l05036"></a>05036         }
<a name="l05037"></a>05037         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ad44c550fab3cb736eb049713ede94052" title="Draw line with alpha blending.">lineColor</a>(dst, *x1, *y1, *vx, *vy, color);
<a name="l05038"></a>05038 
<a name="l05039"></a>05039         <span class="keywordflow">return</span> (result);
<a name="l05040"></a>05040 }
<a name="l05041"></a>05041 
<a name="l05056"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a46b327da5cba5d401cf400bdef7560d0">05056</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae55541ec58990420dc6dc6b9d61f33d6" title="Draw polygon with alpha blending.">polygonRGBA</a>(SDL_Surface * dst, <span class="keyword">const</span> Sint16 * vx, <span class="keyword">const</span> Sint16 * vy, <span class="keywordtype">int</span> n, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l05057"></a>05057 {
<a name="l05058"></a>05058         <span class="comment">/*</span>
<a name="l05059"></a>05059 <span class="comment">        * Draw </span>
<a name="l05060"></a>05060 <span class="comment">        */</span>
<a name="l05061"></a>05061         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a2d692dc25f3b579b386dff8dcd9cbc00" title="Draw polygon with alpha blending.">polygonColor</a>(dst, vx, vy, n, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a));
<a name="l05062"></a>05062 }
<a name="l05063"></a>05063 
<a name="l05064"></a>05064 <span class="comment">/* ---- AA-Polygon */</span>
<a name="l05065"></a>05065 
<a name="l05077"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#acee2be5e220639d3e5c5bc643e091c1c">05077</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a09950a50e8806e88bb20c543c58cc6a8" title="Draw anti-aliased polygon with alpha blending.">aapolygonColor</a>(SDL_Surface * dst, <span class="keyword">const</span> Sint16 * vx, <span class="keyword">const</span> Sint16 * vy, <span class="keywordtype">int</span> n, Uint32 color)
<a name="l05078"></a>05078 {
<a name="l05079"></a>05079         <span class="keywordtype">int</span> result;
<a name="l05080"></a>05080         <span class="keywordtype">int</span> i;
<a name="l05081"></a>05081         <span class="keyword">const</span> Sint16 *x1, *y1, *x2, *y2;
<a name="l05082"></a>05082 
<a name="l05083"></a>05083         <span class="comment">/*</span>
<a name="l05084"></a>05084 <span class="comment">        * Check visibility of clipping rectangle</span>
<a name="l05085"></a>05085 <span class="comment">        */</span>
<a name="l05086"></a>05086         <span class="keywordflow">if</span> ((dst-&gt;clip_rect.w==0) || (dst-&gt;clip_rect.h==0)) {
<a name="l05087"></a>05087                 <span class="keywordflow">return</span>(0);
<a name="l05088"></a>05088         }
<a name="l05089"></a>05089 
<a name="l05090"></a>05090         <span class="comment">/*</span>
<a name="l05091"></a>05091 <span class="comment">        * Vertex array NULL check </span>
<a name="l05092"></a>05092 <span class="comment">        */</span>
<a name="l05093"></a>05093         <span class="keywordflow">if</span> (vx == NULL) {
<a name="l05094"></a>05094                 <span class="keywordflow">return</span> (-1);
<a name="l05095"></a>05095         }
<a name="l05096"></a>05096         <span class="keywordflow">if</span> (vy == NULL) {
<a name="l05097"></a>05097                 <span class="keywordflow">return</span> (-1);
<a name="l05098"></a>05098         }
<a name="l05099"></a>05099 
<a name="l05100"></a>05100         <span class="comment">/*</span>
<a name="l05101"></a>05101 <span class="comment">        * Sanity check </span>
<a name="l05102"></a>05102 <span class="comment">        */</span>
<a name="l05103"></a>05103         <span class="keywordflow">if</span> (n &lt; 3) {
<a name="l05104"></a>05104                 <span class="keywordflow">return</span> (-1);
<a name="l05105"></a>05105         }
<a name="l05106"></a>05106 
<a name="l05107"></a>05107         <span class="comment">/*</span>
<a name="l05108"></a>05108 <span class="comment">        * Pointer setup </span>
<a name="l05109"></a>05109 <span class="comment">        */</span>
<a name="l05110"></a>05110         x1 = x2 = vx;
<a name="l05111"></a>05111         y1 = y2 = vy;
<a name="l05112"></a>05112         x2++;
<a name="l05113"></a>05113         y2++;
<a name="l05114"></a>05114 
<a name="l05115"></a>05115         <span class="comment">/*</span>
<a name="l05116"></a>05116 <span class="comment">        * Draw </span>
<a name="l05117"></a>05117 <span class="comment">        */</span>
<a name="l05118"></a>05118         result = 0;
<a name="l05119"></a>05119         <span class="keywordflow">for</span> (i = 1; i &lt; n; i++) {
<a name="l05120"></a>05120                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a41cb32b84aee2742fabd5bbaced8e016" title="Internal function to draw anti-aliased line with alpha blending and endpoint control.">_aalineColor</a>(dst, *x1, *y1, *x2, *y2, color, 0);
<a name="l05121"></a>05121                 x1 = x2;
<a name="l05122"></a>05122                 y1 = y2;
<a name="l05123"></a>05123                 x2++;
<a name="l05124"></a>05124                 y2++;
<a name="l05125"></a>05125         }
<a name="l05126"></a>05126         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#a41cb32b84aee2742fabd5bbaced8e016" title="Internal function to draw anti-aliased line with alpha blending and endpoint control.">_aalineColor</a>(dst, *x1, *y1, *vx, *vy, color, 0);
<a name="l05127"></a>05127 
<a name="l05128"></a>05128         <span class="keywordflow">return</span> (result);
<a name="l05129"></a>05129 }
<a name="l05130"></a>05130 
<a name="l05145"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#aad73d6fc11bb01946d0ffe1c9d657cb1">05145</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a7d08522e52d8290c5c498ce435fa51f0" title="Draw anti-aliased polygon with alpha blending.">aapolygonRGBA</a>(SDL_Surface * dst, <span class="keyword">const</span> Sint16 * vx, <span class="keyword">const</span> Sint16 * vy, <span class="keywordtype">int</span> n, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l05146"></a>05146 {
<a name="l05147"></a>05147         <span class="comment">/*</span>
<a name="l05148"></a>05148 <span class="comment">        * Draw </span>
<a name="l05149"></a>05149 <span class="comment">        */</span>
<a name="l05150"></a>05150         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a09950a50e8806e88bb20c543c58cc6a8" title="Draw anti-aliased polygon with alpha blending.">aapolygonColor</a>(dst, vx, vy, n, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a));
<a name="l05151"></a>05151 }
<a name="l05152"></a>05152 
<a name="l05153"></a>05153 <span class="comment">/* ---- Filled Polygon */</span>
<a name="l05154"></a>05154 
<a name="l05163"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#aeba347cfe2561fdb7f86d995a941ff1a">05163</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#aeba347cfe2561fdb7f86d995a941ff1a" title="Internal helper qsort callback functions used in filled polygon drawing.">_gfxPrimitivesCompareInt</a>(<span class="keyword">const</span> <span class="keywordtype">void</span> *a, <span class="keyword">const</span> <span class="keywordtype">void</span> *b)
<a name="l05164"></a>05164 {
<a name="l05165"></a>05165         <span class="keywordflow">return</span> (*(<span class="keyword">const</span> <span class="keywordtype">int</span> *) a) - (*(<span class="keyword">const</span> <span class="keywordtype">int</span> *) b);
<a name="l05166"></a>05166 }
<a name="l05167"></a>05167 
<a name="l05173"></a>05173 <span class="keyword">static</span> <span class="keywordtype">int</span> *gfxPrimitivesPolyIntsGlobal = NULL;
<a name="l05174"></a>05174 
<a name="l05180"></a>05180 <span class="keyword">static</span> <span class="keywordtype">int</span> gfxPrimitivesPolyAllocatedGlobal = 0;
<a name="l05181"></a>05181 
<a name="l05197"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a0f5583d5b055f3e59a9692ca8a9dfbcf">05197</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a1f3a2dcda741a2c29b5dacce4ffe0271" title="Draw filled polygon with alpha blending (multi-threaded capable).">filledPolygonColorMT</a>(SDL_Surface * dst, <span class="keyword">const</span> Sint16 * vx, <span class="keyword">const</span> Sint16 * vy, <span class="keywordtype">int</span> n, Uint32 color, <span class="keywordtype">int</span> **polyInts, <span class="keywordtype">int</span> *polyAllocated)
<a name="l05198"></a>05198 {
<a name="l05199"></a>05199         <span class="keywordtype">int</span> result;
<a name="l05200"></a>05200         <span class="keywordtype">int</span> i;
<a name="l05201"></a>05201         <span class="keywordtype">int</span> y, xa, xb;
<a name="l05202"></a>05202         <span class="keywordtype">int</span> miny, maxy;
<a name="l05203"></a>05203         <span class="keywordtype">int</span> x1, y1;
<a name="l05204"></a>05204         <span class="keywordtype">int</span> x2, y2;
<a name="l05205"></a>05205         <span class="keywordtype">int</span> ind1, ind2;
<a name="l05206"></a>05206         <span class="keywordtype">int</span> ints;
<a name="l05207"></a>05207         <span class="keywordtype">int</span> *gfxPrimitivesPolyInts = NULL;
<a name="l05208"></a>05208         <span class="keywordtype">int</span> *gfxPrimitivesPolyIntsNew = NULL;
<a name="l05209"></a>05209         <span class="keywordtype">int</span> gfxPrimitivesPolyAllocated = 0;
<a name="l05210"></a>05210 
<a name="l05211"></a>05211         <span class="comment">/*</span>
<a name="l05212"></a>05212 <span class="comment">        * Check visibility of clipping rectangle</span>
<a name="l05213"></a>05213 <span class="comment">        */</span>
<a name="l05214"></a>05214         <span class="keywordflow">if</span> ((dst-&gt;clip_rect.w==0) || (dst-&gt;clip_rect.h==0)) {
<a name="l05215"></a>05215                 <span class="keywordflow">return</span>(0);
<a name="l05216"></a>05216         }
<a name="l05217"></a>05217 
<a name="l05218"></a>05218         <span class="comment">/*</span>
<a name="l05219"></a>05219 <span class="comment">        * Vertex array NULL check </span>
<a name="l05220"></a>05220 <span class="comment">        */</span>
<a name="l05221"></a>05221         <span class="keywordflow">if</span> (vx == NULL) {
<a name="l05222"></a>05222                 <span class="keywordflow">return</span> (-1);
<a name="l05223"></a>05223         }
<a name="l05224"></a>05224         <span class="keywordflow">if</span> (vy == NULL) {
<a name="l05225"></a>05225                 <span class="keywordflow">return</span> (-1);
<a name="l05226"></a>05226         }
<a name="l05227"></a>05227 
<a name="l05228"></a>05228         <span class="comment">/*</span>
<a name="l05229"></a>05229 <span class="comment">        * Sanity check number of edges</span>
<a name="l05230"></a>05230 <span class="comment">        */</span>
<a name="l05231"></a>05231         <span class="keywordflow">if</span> (n &lt; 3) {
<a name="l05232"></a>05232                 <span class="keywordflow">return</span> -1;
<a name="l05233"></a>05233         }
<a name="l05234"></a>05234 
<a name="l05235"></a>05235         <span class="comment">/*</span>
<a name="l05236"></a>05236 <span class="comment">        * Map polygon cache  </span>
<a name="l05237"></a>05237 <span class="comment">        */</span>
<a name="l05238"></a>05238         <span class="keywordflow">if</span> ((polyInts==NULL) || (polyAllocated==NULL)) {
<a name="l05239"></a>05239                 <span class="comment">/* Use global cache */</span>
<a name="l05240"></a>05240                 gfxPrimitivesPolyInts = gfxPrimitivesPolyIntsGlobal;
<a name="l05241"></a>05241                 gfxPrimitivesPolyAllocated = gfxPrimitivesPolyAllocatedGlobal;
<a name="l05242"></a>05242         } <span class="keywordflow">else</span> {
<a name="l05243"></a>05243                 <span class="comment">/* Use local cache */</span>
<a name="l05244"></a>05244                 gfxPrimitivesPolyInts = *polyInts;
<a name="l05245"></a>05245                 gfxPrimitivesPolyAllocated = *polyAllocated;
<a name="l05246"></a>05246         }
<a name="l05247"></a>05247 
<a name="l05248"></a>05248         <span class="comment">/*</span>
<a name="l05249"></a>05249 <span class="comment">        * Allocate temp array, only grow array </span>
<a name="l05250"></a>05250 <span class="comment">        */</span>
<a name="l05251"></a>05251         <span class="keywordflow">if</span> (!gfxPrimitivesPolyAllocated) {
<a name="l05252"></a>05252                 gfxPrimitivesPolyInts = (<span class="keywordtype">int</span> *) malloc(<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) * n);
<a name="l05253"></a>05253                 gfxPrimitivesPolyAllocated = n;
<a name="l05254"></a>05254         } <span class="keywordflow">else</span> {
<a name="l05255"></a>05255                 <span class="keywordflow">if</span> (gfxPrimitivesPolyAllocated &lt; n) {
<a name="l05256"></a>05256                         gfxPrimitivesPolyIntsNew = (<span class="keywordtype">int</span> *) realloc(gfxPrimitivesPolyInts, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) * n);
<a name="l05257"></a>05257                         <span class="keywordflow">if</span> (!gfxPrimitivesPolyIntsNew) {
<a name="l05258"></a>05258                                 <span class="keywordflow">if</span> (!gfxPrimitivesPolyInts) {
<a name="l05259"></a>05259                                         free(gfxPrimitivesPolyInts);
<a name="l05260"></a>05260                                         gfxPrimitivesPolyInts = NULL;
<a name="l05261"></a>05261                                 }
<a name="l05262"></a>05262                                 gfxPrimitivesPolyAllocated = 0;
<a name="l05263"></a>05263                         } <span class="keywordflow">else</span> {
<a name="l05264"></a>05264                                 gfxPrimitivesPolyInts = gfxPrimitivesPolyIntsNew;
<a name="l05265"></a>05265                                 gfxPrimitivesPolyAllocated = n;
<a name="l05266"></a>05266                         }
<a name="l05267"></a>05267                 }
<a name="l05268"></a>05268         }
<a name="l05269"></a>05269 
<a name="l05270"></a>05270         <span class="comment">/*</span>
<a name="l05271"></a>05271 <span class="comment">        * Check temp array</span>
<a name="l05272"></a>05272 <span class="comment">        */</span>
<a name="l05273"></a>05273         <span class="keywordflow">if</span> (gfxPrimitivesPolyInts==NULL) {        
<a name="l05274"></a>05274                 gfxPrimitivesPolyAllocated = 0;
<a name="l05275"></a>05275         }
<a name="l05276"></a>05276 
<a name="l05277"></a>05277         <span class="comment">/*</span>
<a name="l05278"></a>05278 <span class="comment">        * Update cache variables</span>
<a name="l05279"></a>05279 <span class="comment">        */</span>
<a name="l05280"></a>05280         <span class="keywordflow">if</span> ((polyInts==NULL) || (polyAllocated==NULL)) { 
<a name="l05281"></a>05281                 gfxPrimitivesPolyIntsGlobal =  gfxPrimitivesPolyInts;
<a name="l05282"></a>05282                 gfxPrimitivesPolyAllocatedGlobal = gfxPrimitivesPolyAllocated;
<a name="l05283"></a>05283         } <span class="keywordflow">else</span> {
<a name="l05284"></a>05284                 *polyInts = gfxPrimitivesPolyInts;
<a name="l05285"></a>05285                 *polyAllocated = gfxPrimitivesPolyAllocated;
<a name="l05286"></a>05286         }
<a name="l05287"></a>05287 
<a name="l05288"></a>05288         <span class="comment">/*</span>
<a name="l05289"></a>05289 <span class="comment">        * Check temp array again</span>
<a name="l05290"></a>05290 <span class="comment">        */</span>
<a name="l05291"></a>05291         <span class="keywordflow">if</span> (gfxPrimitivesPolyInts==NULL) {        
<a name="l05292"></a>05292                 <span class="keywordflow">return</span>(-1);
<a name="l05293"></a>05293         }
<a name="l05294"></a>05294 
<a name="l05295"></a>05295         <span class="comment">/*</span>
<a name="l05296"></a>05296 <span class="comment">        * Determine Y maxima </span>
<a name="l05297"></a>05297 <span class="comment">        */</span>
<a name="l05298"></a>05298         miny = vy[0];
<a name="l05299"></a>05299         maxy = vy[0];
<a name="l05300"></a>05300         <span class="keywordflow">for</span> (i = 1; (i &lt; n); i++) {
<a name="l05301"></a>05301                 <span class="keywordflow">if</span> (vy[i] &lt; miny) {
<a name="l05302"></a>05302                         miny = vy[i];
<a name="l05303"></a>05303                 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (vy[i] &gt; maxy) {
<a name="l05304"></a>05304                         maxy = vy[i];
<a name="l05305"></a>05305                 }
<a name="l05306"></a>05306         }
<a name="l05307"></a>05307 
<a name="l05308"></a>05308         <span class="comment">/*</span>
<a name="l05309"></a>05309 <span class="comment">        * Draw, scanning y </span>
<a name="l05310"></a>05310 <span class="comment">        */</span>
<a name="l05311"></a>05311         result = 0;
<a name="l05312"></a>05312         <span class="keywordflow">for</span> (y = miny; (y &lt;= maxy); y++) {
<a name="l05313"></a>05313                 ints = 0;
<a name="l05314"></a>05314                 <span class="keywordflow">for</span> (i = 0; (i &lt; n); i++) {
<a name="l05315"></a>05315                         <span class="keywordflow">if</span> (!i) {
<a name="l05316"></a>05316                                 ind1 = n - 1;
<a name="l05317"></a>05317                                 ind2 = 0;
<a name="l05318"></a>05318                         } <span class="keywordflow">else</span> {
<a name="l05319"></a>05319                                 ind1 = i - 1;
<a name="l05320"></a>05320                                 ind2 = i;
<a name="l05321"></a>05321                         }
<a name="l05322"></a>05322                         y1 = vy[ind1];
<a name="l05323"></a>05323                         y2 = vy[ind2];
<a name="l05324"></a>05324                         <span class="keywordflow">if</span> (y1 &lt; y2) {
<a name="l05325"></a>05325                                 x1 = vx[ind1];
<a name="l05326"></a>05326                                 x2 = vx[ind2];
<a name="l05327"></a>05327                         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (y1 &gt; y2) {
<a name="l05328"></a>05328                                 y2 = vy[ind1];
<a name="l05329"></a>05329                                 y1 = vy[ind2];
<a name="l05330"></a>05330                                 x2 = vx[ind1];
<a name="l05331"></a>05331                                 x1 = vx[ind2];
<a name="l05332"></a>05332                         } <span class="keywordflow">else</span> {
<a name="l05333"></a>05333                                 <span class="keywordflow">continue</span>;
<a name="l05334"></a>05334                         }
<a name="l05335"></a>05335                         <span class="keywordflow">if</span> ( ((y &gt;= y1) &amp;&amp; (y &lt; y2)) || ((y == maxy) &amp;&amp; (y &gt; y1) &amp;&amp; (y &lt;= y2)) ) {
<a name="l05336"></a>05336                                 gfxPrimitivesPolyInts[ints++] = ((65536 * (y - y1)) / (y2 - y1)) * (x2 - x1) + (65536 * x1);
<a name="l05337"></a>05337                         }           
<a name="l05338"></a>05338                 }
<a name="l05339"></a>05339 
<a name="l05340"></a>05340                 qsort(gfxPrimitivesPolyInts, ints, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>), <a class="code" href="_s_d_l__gfx_primitives_8c.html#aeba347cfe2561fdb7f86d995a941ff1a" title="Internal helper qsort callback functions used in filled polygon drawing.">_gfxPrimitivesCompareInt</a>);
<a name="l05341"></a>05341 
<a name="l05342"></a>05342                 <span class="keywordflow">for</span> (i = 0; (i &lt; ints); i += 2) {
<a name="l05343"></a>05343                         xa = gfxPrimitivesPolyInts[i] + 1;
<a name="l05344"></a>05344                         xa = (xa &gt;&gt; 16) + ((xa &amp; 32768) &gt;&gt; 15);
<a name="l05345"></a>05345                         xb = gfxPrimitivesPolyInts[i+1] - 1;
<a name="l05346"></a>05346                         xb = (xb &gt;&gt; 16) + ((xb &amp; 32768) &gt;&gt; 15);
<a name="l05347"></a>05347                         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ac211a904dce45093315e15b10c80d8ac" title="Draw horizontal line with blending.">hlineColor</a>(dst, xa, xb, y, color);
<a name="l05348"></a>05348                 }
<a name="l05349"></a>05349         }
<a name="l05350"></a>05350 
<a name="l05351"></a>05351         <span class="keywordflow">return</span> (result);
<a name="l05352"></a>05352 }
<a name="l05353"></a>05353 
<a name="l05372"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a412cddc17a592c167c060ec2d1d2fd1d">05372</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a586d64a80ac67de184e33609509d45a9" title="Draw filled polygon with alpha blending (multi-threaded capable).">filledPolygonRGBAMT</a>(SDL_Surface * dst, <span class="keyword">const</span> Sint16 * vx, <span class="keyword">const</span> Sint16 * vy, <span class="keywordtype">int</span> n, Uint8 r, Uint8 g, Uint8 b, Uint8 a, <span class="keywordtype">int</span> **polyInts, <span class="keywordtype">int</span> *polyAllocated)
<a name="l05373"></a>05373 {
<a name="l05374"></a>05374         <span class="comment">/*</span>
<a name="l05375"></a>05375 <span class="comment">        * Draw </span>
<a name="l05376"></a>05376 <span class="comment">        */</span>
<a name="l05377"></a>05377         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a1f3a2dcda741a2c29b5dacce4ffe0271" title="Draw filled polygon with alpha blending (multi-threaded capable).">filledPolygonColorMT</a>(dst, vx, vy, n, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a, polyInts, polyAllocated));
<a name="l05378"></a>05378 }
<a name="l05379"></a>05379 
<a name="l05394"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a5e1fe45b835b623f6939ff0f08277531">05394</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#af22692175cb73329410cbcc7d7491c4d" title="Draw filled polygon with alpha blending.">filledPolygonColor</a>(SDL_Surface * dst, <span class="keyword">const</span> Sint16 * vx, <span class="keyword">const</span> Sint16 * vy, <span class="keywordtype">int</span> n, Uint32 color)
<a name="l05395"></a>05395 {
<a name="l05396"></a>05396         <span class="comment">/*</span>
<a name="l05397"></a>05397 <span class="comment">        * Draw </span>
<a name="l05398"></a>05398 <span class="comment">        */</span>
<a name="l05399"></a>05399         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a1f3a2dcda741a2c29b5dacce4ffe0271" title="Draw filled polygon with alpha blending (multi-threaded capable).">filledPolygonColorMT</a>(dst, vx, vy, n, color, NULL, NULL));
<a name="l05400"></a>05400 }
<a name="l05401"></a>05401 
<a name="l05416"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a2b1023ddbbb25d57bd51676b49234af4">05416</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a40ef0b898905c190c193f0f55deb5a6c" title="Draw filled polygon with alpha blending.">filledPolygonRGBA</a>(SDL_Surface * dst, <span class="keyword">const</span> Sint16 * vx, <span class="keyword">const</span> Sint16 * vy, <span class="keywordtype">int</span> n, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l05417"></a>05417 {
<a name="l05418"></a>05418         <span class="comment">/*</span>
<a name="l05419"></a>05419 <span class="comment">        * Draw </span>
<a name="l05420"></a>05420 <span class="comment">        */</span>
<a name="l05421"></a>05421         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a1f3a2dcda741a2c29b5dacce4ffe0271" title="Draw filled polygon with alpha blending (multi-threaded capable).">filledPolygonColorMT</a>(dst, vx, vy, n, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a, NULL, NULL));
<a name="l05422"></a>05422 }
<a name="l05423"></a>05423 
<a name="l05437"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#aba318c28a9d4dfcf6a2e413814979a5a">05437</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#aba318c28a9d4dfcf6a2e413814979a5a" title="Internal function to draw a textured horizontal line.">_HLineTextured</a>(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16 y, SDL_Surface *texture, <span class="keywordtype">int</span> texture_dx, <span class="keywordtype">int</span> texture_dy)
<a name="l05438"></a>05438 {
<a name="l05439"></a>05439         Sint16 left, right, top, bottom;
<a name="l05440"></a>05440         Sint16 w;
<a name="l05441"></a>05441         Sint16 xtmp;
<a name="l05442"></a>05442         <span class="keywordtype">int</span> result = 0;
<a name="l05443"></a>05443         <span class="keywordtype">int</span> texture_x_walker;    
<a name="l05444"></a>05444         <span class="keywordtype">int</span> texture_y_start;    
<a name="l05445"></a>05445         SDL_Rect source_rect,dst_rect;
<a name="l05446"></a>05446         <span class="keywordtype">int</span> pixels_written,write_width;
<a name="l05447"></a>05447 
<a name="l05448"></a>05448         <span class="comment">/*</span>
<a name="l05449"></a>05449 <span class="comment">        * Check visibility of clipping rectangle</span>
<a name="l05450"></a>05450 <span class="comment">        */</span>
<a name="l05451"></a>05451         <span class="keywordflow">if</span> ((dst-&gt;clip_rect.w==0) || (dst-&gt;clip_rect.h==0)) {
<a name="l05452"></a>05452                 <span class="keywordflow">return</span>(0);
<a name="l05453"></a>05453         }
<a name="l05454"></a>05454 
<a name="l05455"></a>05455         <span class="comment">/*</span>
<a name="l05456"></a>05456 <span class="comment">        * Swap x1, x2 if required to ensure x1&lt;=x2</span>
<a name="l05457"></a>05457 <span class="comment">        */</span>
<a name="l05458"></a>05458         <span class="keywordflow">if</span> (x1 &gt; x2) {
<a name="l05459"></a>05459                 xtmp = x1;
<a name="l05460"></a>05460                 x1 = x2;
<a name="l05461"></a>05461                 x2 = xtmp;
<a name="l05462"></a>05462         }
<a name="l05463"></a>05463 
<a name="l05464"></a>05464         <span class="comment">/*</span>
<a name="l05465"></a>05465 <span class="comment">        * Get clipping boundary and</span>
<a name="l05466"></a>05466 <span class="comment">        * check visibility of hline </span>
<a name="l05467"></a>05467 <span class="comment">        */</span>
<a name="l05468"></a>05468         left = dst-&gt;clip_rect.x;
<a name="l05469"></a>05469         <span class="keywordflow">if</span> (x2&lt;left) {
<a name="l05470"></a>05470                 <span class="keywordflow">return</span>(0);
<a name="l05471"></a>05471         }
<a name="l05472"></a>05472         right = dst-&gt;clip_rect.x + dst-&gt;clip_rect.w - 1;
<a name="l05473"></a>05473         <span class="keywordflow">if</span> (x1&gt;right) {
<a name="l05474"></a>05474                 <span class="keywordflow">return</span>(0);
<a name="l05475"></a>05475         }
<a name="l05476"></a>05476         top = dst-&gt;clip_rect.y;
<a name="l05477"></a>05477         bottom = dst-&gt;clip_rect.y + dst-&gt;clip_rect.h - 1;
<a name="l05478"></a>05478         <span class="keywordflow">if</span> ((y&lt;top) || (y&gt;bottom)) {
<a name="l05479"></a>05479                 <span class="keywordflow">return</span> (0);
<a name="l05480"></a>05480         }
<a name="l05481"></a>05481 
<a name="l05482"></a>05482         <span class="comment">/*</span>
<a name="l05483"></a>05483 <span class="comment">        * Clip x </span>
<a name="l05484"></a>05484 <span class="comment">        */</span>
<a name="l05485"></a>05485         <span class="keywordflow">if</span> (x1 &lt; left) {
<a name="l05486"></a>05486                 x1 = left;
<a name="l05487"></a>05487         }
<a name="l05488"></a>05488         <span class="keywordflow">if</span> (x2 &gt; right) {
<a name="l05489"></a>05489                 x2 = right;
<a name="l05490"></a>05490         }
<a name="l05491"></a>05491 
<a name="l05492"></a>05492         <span class="comment">/*</span>
<a name="l05493"></a>05493 <span class="comment">        * Calculate width to draw</span>
<a name="l05494"></a>05494 <span class="comment">        */</span>
<a name="l05495"></a>05495         w = x2 - x1 + 1;
<a name="l05496"></a>05496 
<a name="l05497"></a>05497         <span class="comment">/*</span>
<a name="l05498"></a>05498 <span class="comment">        * Determine where in the texture we start drawing</span>
<a name="l05499"></a>05499 <span class="comment">        */</span>
<a name="l05500"></a>05500         texture_x_walker =   (x1 - texture_dx)  % texture-&gt;w;
<a name="l05501"></a>05501         if (texture_x_walker &lt; 0){
<a name="l05502"></a>05502                 texture_x_walker = texture-&gt;w + texture_x_walker ;
<a name="l05503"></a>05503         }
<a name="l05504"></a>05504 
<a name="l05505"></a>05505         texture_y_start = (y + texture_dy) % texture-&gt;h;
<a name="l05506"></a>05506         if (texture_y_start &lt; 0){
<a name="l05507"></a>05507                 texture_y_start = texture-&gt;h + texture_y_start;
<a name="l05508"></a>05508         }
<a name="l05509"></a>05509 
<a name="l05510"></a>05510         <span class="comment">// setup the source rectangle; we are only drawing one horizontal line</span>
<a name="l05511"></a>05511         source_rect.y = texture_y_start;
<a name="l05512"></a>05512         source_rect.x = texture_x_walker;
<a name="l05513"></a>05513         source_rect.h = 1;
<a name="l05514"></a>05514 
<a name="l05515"></a>05515         <span class="comment">// we will draw to the current y</span>
<a name="l05516"></a>05516         dst_rect.y = y;
<a name="l05517"></a>05517 
<a name="l05518"></a>05518         <span class="comment">// if there are enough pixels left in the current row of the texture</span>
<a name="l05519"></a>05519         <span class="comment">// draw it all at once</span>
<a name="l05520"></a>05520         <span class="keywordflow">if</span> (w &lt;= texture-&gt;w -texture_x_walker){
<a name="l05521"></a>05521                 source_rect.w = w;
<a name="l05522"></a>05522                 source_rect.x = texture_x_walker;
<a name="l05523"></a>05523                 dst_rect.x= x1;
<a name="l05524"></a>05524                 result = (SDL_BlitSurface  (texture, &amp;source_rect , dst, &amp;dst_rect) == 0);
<a name="l05525"></a>05525         } <span class="keywordflow">else</span> { <span class="comment">// we need to draw multiple times</span>
<a name="l05526"></a>05526                 <span class="comment">// draw the first segment</span>
<a name="l05527"></a>05527                 pixels_written = texture-&gt;w  - texture_x_walker;
<a name="l05528"></a>05528                 source_rect.w = pixels_written;
<a name="l05529"></a>05529                 source_rect.x = texture_x_walker;
<a name="l05530"></a>05530                 dst_rect.x= x1;
<a name="l05531"></a>05531                 result |= (SDL_BlitSurface (texture, &amp;source_rect , dst, &amp;dst_rect) == 0);
<a name="l05532"></a>05532                 write_width = texture-&gt;w;
<a name="l05533"></a>05533 
<a name="l05534"></a>05534                 <span class="comment">// now draw the rest</span>
<a name="l05535"></a>05535                 <span class="comment">// set the source x to 0</span>
<a name="l05536"></a>05536                 source_rect.x = 0;
<a name="l05537"></a>05537                 <span class="keywordflow">while</span> (pixels_written &lt; w){
<a name="l05538"></a>05538                         <span class="keywordflow">if</span> (write_width &gt;= w - pixels_written) {
<a name="l05539"></a>05539                                 write_width =  w - pixels_written;
<a name="l05540"></a>05540                         }
<a name="l05541"></a>05541                         source_rect.w = write_width;
<a name="l05542"></a>05542                         dst_rect.x = x1 + pixels_written;
<a name="l05543"></a>05543                         result  |= (SDL_BlitSurface  (texture,&amp;source_rect , dst, &amp;dst_rect) == 0);
<a name="l05544"></a>05544                         pixels_written += write_width;
<a name="l05545"></a>05545                 }
<a name="l05546"></a>05546         }
<a name="l05547"></a>05547 
<a name="l05548"></a>05548         <span class="keywordflow">return</span> result;
<a name="l05549"></a>05549 }
<a name="l05550"></a>05550 
<a name="l05574"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a326937a19cfbebea09aa0a7c908d89aa">05574</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a28ae354c6272da21b5753ae4ab9e1e84" title="Draws a polygon filled with the given texture (Multi-Threading Capable).">texturedPolygonMT</a>(SDL_Surface * dst, <span class="keyword">const</span> Sint16 * vx, <span class="keyword">const</span> Sint16 * vy, <span class="keywordtype">int</span> n, 
<a name="l05575"></a>05575         SDL_Surface * texture, <span class="keywordtype">int</span> texture_dx, <span class="keywordtype">int</span> texture_dy, <span class="keywordtype">int</span> **polyInts, <span class="keywordtype">int</span> *polyAllocated)
<a name="l05576"></a>05576 {
<a name="l05577"></a>05577         <span class="keywordtype">int</span> result;
<a name="l05578"></a>05578         <span class="keywordtype">int</span> i;
<a name="l05579"></a>05579         <span class="keywordtype">int</span> y, xa, xb;
<a name="l05580"></a>05580         <span class="keywordtype">int</span> minx,maxx,miny, maxy;
<a name="l05581"></a>05581         <span class="keywordtype">int</span> x1, y1;
<a name="l05582"></a>05582         <span class="keywordtype">int</span> x2, y2;
<a name="l05583"></a>05583         <span class="keywordtype">int</span> ind1, ind2;
<a name="l05584"></a>05584         <span class="keywordtype">int</span> ints;
<a name="l05585"></a>05585         <span class="keywordtype">int</span> *gfxPrimitivesPolyInts = NULL;
<a name="l05586"></a>05586         <span class="keywordtype">int</span> gfxPrimitivesPolyAllocated = 0;
<a name="l05587"></a>05587 
<a name="l05588"></a>05588         <span class="comment">/*</span>
<a name="l05589"></a>05589 <span class="comment">        * Check visibility of clipping rectangle</span>
<a name="l05590"></a>05590 <span class="comment">        */</span>
<a name="l05591"></a>05591         <span class="keywordflow">if</span> ((dst-&gt;clip_rect.w==0) || (dst-&gt;clip_rect.h==0)) {
<a name="l05592"></a>05592                 <span class="keywordflow">return</span>(0);
<a name="l05593"></a>05593         }
<a name="l05594"></a>05594 
<a name="l05595"></a>05595         <span class="comment">/*</span>
<a name="l05596"></a>05596 <span class="comment">        * Sanity check number of edges</span>
<a name="l05597"></a>05597 <span class="comment">        */</span>
<a name="l05598"></a>05598         <span class="keywordflow">if</span> (n &lt; 3) {
<a name="l05599"></a>05599                 <span class="keywordflow">return</span> -1;
<a name="l05600"></a>05600         }
<a name="l05601"></a>05601 
<a name="l05602"></a>05602         <span class="comment">/*</span>
<a name="l05603"></a>05603 <span class="comment">        * Map polygon cache  </span>
<a name="l05604"></a>05604 <span class="comment">        */</span>
<a name="l05605"></a>05605         <span class="keywordflow">if</span> ((polyInts==NULL) || (polyAllocated==NULL)) {
<a name="l05606"></a>05606                 <span class="comment">/* Use global cache */</span>
<a name="l05607"></a>05607                 gfxPrimitivesPolyInts = gfxPrimitivesPolyIntsGlobal;
<a name="l05608"></a>05608                 gfxPrimitivesPolyAllocated = gfxPrimitivesPolyAllocatedGlobal;
<a name="l05609"></a>05609         } <span class="keywordflow">else</span> {
<a name="l05610"></a>05610                 <span class="comment">/* Use local cache */</span>
<a name="l05611"></a>05611                 gfxPrimitivesPolyInts = *polyInts;
<a name="l05612"></a>05612                 gfxPrimitivesPolyAllocated = *polyAllocated;
<a name="l05613"></a>05613         }
<a name="l05614"></a>05614 
<a name="l05615"></a>05615         <span class="comment">/*</span>
<a name="l05616"></a>05616 <span class="comment">        * Allocate temp array, only grow array </span>
<a name="l05617"></a>05617 <span class="comment">        */</span>
<a name="l05618"></a>05618         <span class="keywordflow">if</span> (!gfxPrimitivesPolyAllocated) {
<a name="l05619"></a>05619                 gfxPrimitivesPolyInts = (<span class="keywordtype">int</span> *) malloc(<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) * n);
<a name="l05620"></a>05620                 gfxPrimitivesPolyAllocated = n;
<a name="l05621"></a>05621         } <span class="keywordflow">else</span> {
<a name="l05622"></a>05622                 <span class="keywordflow">if</span> (gfxPrimitivesPolyAllocated &lt; n) {
<a name="l05623"></a>05623                         gfxPrimitivesPolyInts = (<span class="keywordtype">int</span> *) realloc(gfxPrimitivesPolyInts, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) * n);
<a name="l05624"></a>05624                         gfxPrimitivesPolyAllocated = n;
<a name="l05625"></a>05625                 }
<a name="l05626"></a>05626         }
<a name="l05627"></a>05627 
<a name="l05628"></a>05628         <span class="comment">/*</span>
<a name="l05629"></a>05629 <span class="comment">        * Check temp array</span>
<a name="l05630"></a>05630 <span class="comment">        */</span>
<a name="l05631"></a>05631         <span class="keywordflow">if</span> (gfxPrimitivesPolyInts==NULL) {        
<a name="l05632"></a>05632                 gfxPrimitivesPolyAllocated = 0;
<a name="l05633"></a>05633         }
<a name="l05634"></a>05634 
<a name="l05635"></a>05635         <span class="comment">/*</span>
<a name="l05636"></a>05636 <span class="comment">        * Update cache variables</span>
<a name="l05637"></a>05637 <span class="comment">        */</span>
<a name="l05638"></a>05638         <span class="keywordflow">if</span> ((polyInts==NULL) || (polyAllocated==NULL)) { 
<a name="l05639"></a>05639                 gfxPrimitivesPolyIntsGlobal =  gfxPrimitivesPolyInts;
<a name="l05640"></a>05640                 gfxPrimitivesPolyAllocatedGlobal = gfxPrimitivesPolyAllocated;
<a name="l05641"></a>05641         } <span class="keywordflow">else</span> {
<a name="l05642"></a>05642                 *polyInts = gfxPrimitivesPolyInts;
<a name="l05643"></a>05643                 *polyAllocated = gfxPrimitivesPolyAllocated;
<a name="l05644"></a>05644         }
<a name="l05645"></a>05645 
<a name="l05646"></a>05646         <span class="comment">/*</span>
<a name="l05647"></a>05647 <span class="comment">        * Check temp array again</span>
<a name="l05648"></a>05648 <span class="comment">        */</span>
<a name="l05649"></a>05649         <span class="keywordflow">if</span> (gfxPrimitivesPolyInts==NULL) {        
<a name="l05650"></a>05650                 <span class="keywordflow">return</span>(-1);
<a name="l05651"></a>05651         }
<a name="l05652"></a>05652 
<a name="l05653"></a>05653         <span class="comment">/*</span>
<a name="l05654"></a>05654 <span class="comment">        * Determine X,Y minima,maxima </span>
<a name="l05655"></a>05655 <span class="comment">        */</span>
<a name="l05656"></a>05656         miny = vy[0];
<a name="l05657"></a>05657         maxy = vy[0];
<a name="l05658"></a>05658         minx = vx[0];
<a name="l05659"></a>05659         maxx = vx[0];
<a name="l05660"></a>05660         <span class="keywordflow">for</span> (i = 1; (i &lt; n); i++) {
<a name="l05661"></a>05661                 <span class="keywordflow">if</span> (vy[i] &lt; miny) {
<a name="l05662"></a>05662                         miny = vy[i];
<a name="l05663"></a>05663                 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (vy[i] &gt; maxy) {
<a name="l05664"></a>05664                         maxy = vy[i];
<a name="l05665"></a>05665                 }
<a name="l05666"></a>05666                 <span class="keywordflow">if</span> (vx[i] &lt; minx) {
<a name="l05667"></a>05667                         minx = vx[i];
<a name="l05668"></a>05668                 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (vx[i] &gt; maxx) {
<a name="l05669"></a>05669                         maxx = vx[i];
<a name="l05670"></a>05670                 }
<a name="l05671"></a>05671         }
<a name="l05672"></a>05672         <span class="keywordflow">if</span> (maxx &lt;0 || minx &gt; dst-&gt;w){
<a name="l05673"></a>05673                 <span class="keywordflow">return</span> -1;
<a name="l05674"></a>05674         }
<a name="l05675"></a>05675         <span class="keywordflow">if</span> (maxy &lt;0 || miny &gt; dst-&gt;h){
<a name="l05676"></a>05676                 <span class="keywordflow">return</span> -1;
<a name="l05677"></a>05677         }
<a name="l05678"></a>05678 
<a name="l05679"></a>05679         <span class="comment">/*</span>
<a name="l05680"></a>05680 <span class="comment">        * Draw, scanning y </span>
<a name="l05681"></a>05681 <span class="comment">        */</span>
<a name="l05682"></a>05682         result = 0;
<a name="l05683"></a>05683         <span class="keywordflow">for</span> (y = miny; (y &lt;= maxy); y++) {
<a name="l05684"></a>05684                 ints = 0;
<a name="l05685"></a>05685                 <span class="keywordflow">for</span> (i = 0; (i &lt; n); i++) {
<a name="l05686"></a>05686                         <span class="keywordflow">if</span> (!i) {
<a name="l05687"></a>05687                                 ind1 = n - 1;
<a name="l05688"></a>05688                                 ind2 = 0;
<a name="l05689"></a>05689                         } <span class="keywordflow">else</span> {
<a name="l05690"></a>05690                                 ind1 = i - 1;
<a name="l05691"></a>05691                                 ind2 = i;
<a name="l05692"></a>05692                         }
<a name="l05693"></a>05693                         y1 = vy[ind1];
<a name="l05694"></a>05694                         y2 = vy[ind2];
<a name="l05695"></a>05695                         <span class="keywordflow">if</span> (y1 &lt; y2) {
<a name="l05696"></a>05696                                 x1 = vx[ind1];
<a name="l05697"></a>05697                                 x2 = vx[ind2];
<a name="l05698"></a>05698                         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (y1 &gt; y2) {
<a name="l05699"></a>05699                                 y2 = vy[ind1];
<a name="l05700"></a>05700                                 y1 = vy[ind2];
<a name="l05701"></a>05701                                 x2 = vx[ind1];
<a name="l05702"></a>05702                                 x1 = vx[ind2];
<a name="l05703"></a>05703                         } <span class="keywordflow">else</span> {
<a name="l05704"></a>05704                                 <span class="keywordflow">continue</span>;
<a name="l05705"></a>05705                         }
<a name="l05706"></a>05706                         <span class="keywordflow">if</span> ( ((y &gt;= y1) &amp;&amp; (y &lt; y2)) || ((y == maxy) &amp;&amp; (y &gt; y1) &amp;&amp; (y &lt;= y2)) ) {
<a name="l05707"></a>05707                                 gfxPrimitivesPolyInts[ints++] = ((65536 * (y - y1)) / (y2 - y1)) * (x2 - x1) + (65536 * x1);
<a name="l05708"></a>05708                         } 
<a name="l05709"></a>05709                 }
<a name="l05710"></a>05710 
<a name="l05711"></a>05711                 qsort(gfxPrimitivesPolyInts, ints, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>), <a class="code" href="_s_d_l__gfx_primitives_8c.html#aeba347cfe2561fdb7f86d995a941ff1a" title="Internal helper qsort callback functions used in filled polygon drawing.">_gfxPrimitivesCompareInt</a>);
<a name="l05712"></a>05712 
<a name="l05713"></a>05713                 <span class="keywordflow">for</span> (i = 0; (i &lt; ints); i += 2) {
<a name="l05714"></a>05714                         xa = gfxPrimitivesPolyInts[i] + 1;
<a name="l05715"></a>05715                         xa = (xa &gt;&gt; 16) + ((xa &amp; 32768) &gt;&gt; 15);
<a name="l05716"></a>05716                         xb = gfxPrimitivesPolyInts[i+1] - 1;
<a name="l05717"></a>05717                         xb = (xb &gt;&gt; 16) + ((xb &amp; 32768) &gt;&gt; 15);
<a name="l05718"></a>05718                         result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#aba318c28a9d4dfcf6a2e413814979a5a" title="Internal function to draw a textured horizontal line.">_HLineTextured</a>(dst, xa, xb, y, texture, texture_dx, texture_dy);
<a name="l05719"></a>05719                 }
<a name="l05720"></a>05720         }
<a name="l05721"></a>05721 
<a name="l05722"></a>05722         <span class="keywordflow">return</span> (result);
<a name="l05723"></a>05723 }
<a name="l05724"></a>05724 
<a name="l05741"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a5ca5a9bcfeba5b1a1577202e79b494d8">05741</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a65137af308ea878f28abc95419e8aef5" title="Draws a polygon filled with the given texture.">texturedPolygon</a>(SDL_Surface * dst, <span class="keyword">const</span> Sint16 * vx, <span class="keyword">const</span> Sint16 * vy, <span class="keywordtype">int</span> n, SDL_Surface *texture, <span class="keywordtype">int</span> texture_dx, <span class="keywordtype">int</span> texture_dy)
<a name="l05742"></a>05742 {
<a name="l05743"></a>05743         <span class="comment">/*</span>
<a name="l05744"></a>05744 <span class="comment">        * Draw</span>
<a name="l05745"></a>05745 <span class="comment">        */</span>
<a name="l05746"></a>05746         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a28ae354c6272da21b5753ae4ab9e1e84" title="Draws a polygon filled with the given texture (Multi-Threading Capable).">texturedPolygonMT</a>(dst, vx, vy, n, texture, texture_dx, texture_dy, NULL, NULL));
<a name="l05747"></a>05747 }
<a name="l05748"></a>05748 
<a name="l05749"></a>05749 
<a name="l05750"></a>05750 <span class="comment">/* ---- Character */</span>
<a name="l05751"></a>05751 
<a name="l05755"></a>05755 <span class="keyword">static</span> SDL_Surface *gfxPrimitivesFont[256];
<a name="l05756"></a>05756 
<a name="l05760"></a>05760 <span class="keyword">static</span> Uint32 gfxPrimitivesFontColor[256];
<a name="l05761"></a>05761 
<a name="l05765"></a>05765 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *currentFontdata = gfxPrimitivesFontdata;
<a name="l05766"></a>05766 
<a name="l05770"></a>05770 <span class="keyword">static</span> Uint32 charWidth = 8;
<a name="l05771"></a>05771 
<a name="l05775"></a>05775 <span class="keyword">static</span> Uint32 charHeight = 8;
<a name="l05776"></a>05776 
<a name="l05780"></a>05780 <span class="keyword">static</span> Uint32 charWidthLocal = 8;
<a name="l05781"></a>05781 
<a name="l05785"></a>05785 <span class="keyword">static</span> Uint32 charHeightLocal = 8;
<a name="l05786"></a>05786 
<a name="l05790"></a>05790 <span class="keyword">static</span> Uint32 charPitch = 1;
<a name="l05791"></a>05791 
<a name="l05795"></a>05795 <span class="keyword">static</span> Uint32 charRotation = 0;
<a name="l05796"></a>05796 
<a name="l05800"></a>05800 <span class="keyword">static</span> Uint32 charSize = 8;
<a name="l05801"></a>05801 
<a name="l05815"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a7cabe806643c19159948639faaf26a38">05815</a> <span class="keywordtype">void</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#afacd57651ec0e0ccab60753636862cd0" title="Sets or resets the current global font data.">gfxPrimitivesSetFont</a>(<span class="keyword">const</span> <span class="keywordtype">void</span> *fontdata, Uint32 cw, Uint32 ch)
<a name="l05816"></a>05816 {
<a name="l05817"></a>05817         <span class="keywordtype">int</span> i;
<a name="l05818"></a>05818 
<a name="l05819"></a>05819         <span class="keywordflow">if</span> ((fontdata) &amp;&amp; (cw) &amp;&amp; (ch)) {
<a name="l05820"></a>05820                 currentFontdata = fontdata;
<a name="l05821"></a>05821                 charWidth = cw;
<a name="l05822"></a>05822                 charHeight = ch;
<a name="l05823"></a>05823         } <span class="keywordflow">else</span> {
<a name="l05824"></a>05824                 currentFontdata = gfxPrimitivesFontdata;
<a name="l05825"></a>05825                 charWidth = 8;
<a name="l05826"></a>05826                 charHeight = 8;
<a name="l05827"></a>05827         }
<a name="l05828"></a>05828 
<a name="l05829"></a>05829         charPitch = (charWidth+7)/8;
<a name="l05830"></a>05830         charSize = charPitch * charHeight;
<a name="l05831"></a>05831 
<a name="l05832"></a>05832         <span class="comment">/* Maybe flip width/height for rendering */</span>
<a name="l05833"></a>05833         <span class="keywordflow">if</span> ((charRotation==1) || (charRotation==3))
<a name="l05834"></a>05834         {
<a name="l05835"></a>05835                 charWidthLocal = charHeight;
<a name="l05836"></a>05836                 charHeightLocal = charWidth;
<a name="l05837"></a>05837         }
<a name="l05838"></a>05838         <span class="keywordflow">else</span>
<a name="l05839"></a>05839         {
<a name="l05840"></a>05840                 charWidthLocal = charWidth;
<a name="l05841"></a>05841                 charHeightLocal = charHeight;
<a name="l05842"></a>05842         }
<a name="l05843"></a>05843 
<a name="l05844"></a>05844         <span class="comment">/* Clear character cache */</span>
<a name="l05845"></a>05845         <span class="keywordflow">for</span> (i = 0; i &lt; 256; i++) {
<a name="l05846"></a>05846                 <span class="keywordflow">if</span> (gfxPrimitivesFont[i]) {
<a name="l05847"></a>05847                         SDL_FreeSurface(gfxPrimitivesFont[i]);
<a name="l05848"></a>05848                         gfxPrimitivesFont[i] = NULL;
<a name="l05849"></a>05849                 }
<a name="l05850"></a>05850         }
<a name="l05851"></a>05851 }
<a name="l05852"></a>05852 
<a name="l05861"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a77cc480ba039c758d1cf0cd43db04bd6">05861</a> <span class="keywordtype">void</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#aef6796a883f07d31bbf7c7df6d1153d2" title="Sets current global font character rotation steps.">gfxPrimitivesSetFontRotation</a>(Uint32 rotation)
<a name="l05862"></a>05862 {
<a name="l05863"></a>05863         <span class="keywordtype">int</span> i;
<a name="l05864"></a>05864 
<a name="l05865"></a>05865         rotation = rotation &amp; 3;
<a name="l05866"></a>05866         <span class="keywordflow">if</span> (charRotation != rotation)
<a name="l05867"></a>05867         {
<a name="l05868"></a>05868                 <span class="comment">/* Store rotation */</span>
<a name="l05869"></a>05869                 charRotation = rotation;
<a name="l05870"></a>05870 
<a name="l05871"></a>05871                 <span class="comment">/* Maybe flip width/height for rendering */</span>
<a name="l05872"></a>05872                 <span class="keywordflow">if</span> ((charRotation==1) || (charRotation==3))
<a name="l05873"></a>05873                 {
<a name="l05874"></a>05874                         charWidthLocal = charHeight;
<a name="l05875"></a>05875                         charHeightLocal = charWidth;
<a name="l05876"></a>05876                 }
<a name="l05877"></a>05877                 <span class="keywordflow">else</span>
<a name="l05878"></a>05878                 {
<a name="l05879"></a>05879                         charWidthLocal = charWidth;
<a name="l05880"></a>05880                         charHeightLocal = charHeight;
<a name="l05881"></a>05881                 }
<a name="l05882"></a>05882 
<a name="l05883"></a>05883                 <span class="comment">/* Clear character cache */</span>
<a name="l05884"></a>05884                 <span class="keywordflow">for</span> (i = 0; i &lt; 256; i++) {
<a name="l05885"></a>05885                         <span class="keywordflow">if</span> (gfxPrimitivesFont[i]) {
<a name="l05886"></a>05886                                 SDL_FreeSurface(gfxPrimitivesFont[i]);
<a name="l05887"></a>05887                                 gfxPrimitivesFont[i] = NULL;
<a name="l05888"></a>05888                         }
<a name="l05889"></a>05889                 }
<a name="l05890"></a>05890         }
<a name="l05891"></a>05891 }
<a name="l05892"></a>05892 
<a name="l05908"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#af1991f2031346131db4ae8fd40492b08">05908</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#aef5fdeb16c4578d8cd50e106299e993e" title="Draw a character of the currently set font.">characterColor</a>(SDL_Surface * dst, Sint16 x, Sint16 y, <span class="keywordtype">char</span> c, Uint32 color)
<a name="l05909"></a>05909 {
<a name="l05910"></a>05910         Sint16 left, right, top, bottom;
<a name="l05911"></a>05911         Sint16 x1, y1, x2, y2;
<a name="l05912"></a>05912         SDL_Rect srect;
<a name="l05913"></a>05913         SDL_Rect drect;
<a name="l05914"></a>05914         <span class="keywordtype">int</span> result;
<a name="l05915"></a>05915         Uint32 ix, iy;
<a name="l05916"></a>05916         <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *charpos;
<a name="l05917"></a>05917         Uint8 *curpos;
<a name="l05918"></a>05918         <span class="keywordtype">int</span> forced_redraw;
<a name="l05919"></a>05919         Uint8 patt, mask;
<a name="l05920"></a>05920         Uint8 *linepos;
<a name="l05921"></a>05921         Uint32 pitch;
<a name="l05922"></a>05922         SDL_Surface *rotatedCharacter;
<a name="l05923"></a>05923         Uint32 ci;
<a name="l05924"></a>05924 
<a name="l05925"></a>05925         <span class="comment">/*</span>
<a name="l05926"></a>05926 <span class="comment">        * Check visibility of clipping rectangle</span>
<a name="l05927"></a>05927 <span class="comment">        */</span>
<a name="l05928"></a>05928         <span class="keywordflow">if</span> ((dst-&gt;clip_rect.w==0) || (dst-&gt;clip_rect.h==0)) {
<a name="l05929"></a>05929                 <span class="keywordflow">return</span>(0);
<a name="l05930"></a>05930         }
<a name="l05931"></a>05931 
<a name="l05932"></a>05932         <span class="comment">/*</span>
<a name="l05933"></a>05933 <span class="comment">        * Get text and clipping boundary and</span>
<a name="l05934"></a>05934 <span class="comment">        * test if bounding box of character is visible </span>
<a name="l05935"></a>05935 <span class="comment">        */</span>
<a name="l05936"></a>05936 
<a name="l05937"></a>05937         left = dst-&gt;clip_rect.x;
<a name="l05938"></a>05938         x2 = x + charWidthLocal;
<a name="l05939"></a>05939         <span class="keywordflow">if</span> (x2&lt;left) {
<a name="l05940"></a>05940                 <span class="keywordflow">return</span>(0);
<a name="l05941"></a>05941         } 
<a name="l05942"></a>05942         right = dst-&gt;clip_rect.x + dst-&gt;clip_rect.w - 1;
<a name="l05943"></a>05943         x1 = x;
<a name="l05944"></a>05944         <span class="keywordflow">if</span> (x1&gt;right) {
<a name="l05945"></a>05945                 <span class="keywordflow">return</span>(0);
<a name="l05946"></a>05946         } 
<a name="l05947"></a>05947         top = dst-&gt;clip_rect.y;
<a name="l05948"></a>05948         y2 = y + charHeightLocal;
<a name="l05949"></a>05949         <span class="keywordflow">if</span> (y2&lt;top) {
<a name="l05950"></a>05950                 <span class="keywordflow">return</span>(0);
<a name="l05951"></a>05951         } 
<a name="l05952"></a>05952         bottom = dst-&gt;clip_rect.y + dst-&gt;clip_rect.h - 1;
<a name="l05953"></a>05953         y1 = y;
<a name="l05954"></a>05954         <span class="keywordflow">if</span> (y1&gt;bottom) {
<a name="l05955"></a>05955                 <span class="keywordflow">return</span>(0);
<a name="l05956"></a>05956         } 
<a name="l05957"></a>05957 
<a name="l05958"></a>05958         <span class="comment">/*</span>
<a name="l05959"></a>05959 <span class="comment">        * Setup source rectangle</span>
<a name="l05960"></a>05960 <span class="comment">        */</span>
<a name="l05961"></a>05961         srect.x = 0;
<a name="l05962"></a>05962         srect.y = 0;
<a name="l05963"></a>05963         srect.w = charWidthLocal;
<a name="l05964"></a>05964         srect.h = charHeightLocal;
<a name="l05965"></a>05965 
<a name="l05966"></a>05966         <span class="comment">/*</span>
<a name="l05967"></a>05967 <span class="comment">        * Setup destination rectangle</span>
<a name="l05968"></a>05968 <span class="comment">        */</span>
<a name="l05969"></a>05969         drect.x = x;
<a name="l05970"></a>05970         drect.y = y;
<a name="l05971"></a>05971         drect.w = charWidthLocal;
<a name="l05972"></a>05972         drect.h = charHeightLocal;
<a name="l05973"></a>05973 
<a name="l05974"></a>05974         <span class="comment">/* Character index in cache */</span>
<a name="l05975"></a>05975         ci = (<span class="keywordtype">unsigned</span> char) c;
<a name="l05976"></a>05976 
<a name="l05977"></a>05977         <span class="comment">/*</span>
<a name="l05978"></a>05978 <span class="comment">        * Create new charWidth x charHeight bitmap surface if not already present.</span>
<a name="l05979"></a>05979 <span class="comment">        * Might get rotated later.</span>
<a name="l05980"></a>05980 <span class="comment">        */</span>
<a name="l05981"></a>05981         <span class="keywordflow">if</span> (gfxPrimitivesFont[ci] == NULL) {
<a name="l05982"></a>05982                 gfxPrimitivesFont[ci] =
<a name="l05983"></a>05983                         SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_HWSURFACE | SDL_SRCALPHA,
<a name="l05984"></a>05984                         charWidth, charHeight, 32,
<a name="l05985"></a>05985                         0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
<a name="l05986"></a>05986                 <span class="comment">/*</span>
<a name="l05987"></a>05987 <span class="comment">                * Check pointer </span>
<a name="l05988"></a>05988 <span class="comment">                */</span>
<a name="l05989"></a>05989                 <span class="keywordflow">if</span> (gfxPrimitivesFont[ci] == NULL) {
<a name="l05990"></a>05990                         <span class="keywordflow">return</span> (-1);
<a name="l05991"></a>05991                 }
<a name="l05992"></a>05992                 <span class="comment">/*</span>
<a name="l05993"></a>05993 <span class="comment">                * Definitely redraw </span>
<a name="l05994"></a>05994 <span class="comment">                */</span>
<a name="l05995"></a>05995                 forced_redraw = 1;
<a name="l05996"></a>05996         } <span class="keywordflow">else</span> {
<a name="l05997"></a>05997                 forced_redraw = 0;
<a name="l05998"></a>05998         }
<a name="l05999"></a>05999 
<a name="l06000"></a>06000         <span class="comment">/*</span>
<a name="l06001"></a>06001 <span class="comment">        * Check if color has changed </span>
<a name="l06002"></a>06002 <span class="comment">        */</span>
<a name="l06003"></a>06003         <span class="keywordflow">if</span> ((gfxPrimitivesFontColor[ci] != color) || (forced_redraw)) {
<a name="l06004"></a>06004                 <span class="comment">/*</span>
<a name="l06005"></a>06005 <span class="comment">                * Redraw character </span>
<a name="l06006"></a>06006 <span class="comment">                */</span>
<a name="l06007"></a>06007                 SDL_SetAlpha(gfxPrimitivesFont[ci], SDL_SRCALPHA, 255);
<a name="l06008"></a>06008                 gfxPrimitivesFontColor[ci] = color;
<a name="l06009"></a>06009 
<a name="l06010"></a>06010                 <span class="comment">/* Lock font-surface */</span>
<a name="l06011"></a>06011                 <span class="keywordflow">if</span> (SDL_LockSurface(gfxPrimitivesFont[ci]) != 0)
<a name="l06012"></a>06012                         <span class="keywordflow">return</span> (-1);
<a name="l06013"></a>06013 
<a name="l06014"></a>06014                 <span class="comment">/*</span>
<a name="l06015"></a>06015 <span class="comment">                * Variable setup </span>
<a name="l06016"></a>06016 <span class="comment">                */</span>
<a name="l06017"></a>06017                 charpos = currentFontdata + ci * charSize;
<a name="l06018"></a>06018                 linepos = (Uint8 *) gfxPrimitivesFont[ci]-&gt;pixels;
<a name="l06019"></a>06019                 pitch = gfxPrimitivesFont[ci]-&gt;pitch;
<a name="l06020"></a>06020 
<a name="l06021"></a>06021                 <span class="comment">/*</span>
<a name="l06022"></a>06022 <span class="comment">                * Drawing loop </span>
<a name="l06023"></a>06023 <span class="comment">                */</span>
<a name="l06024"></a>06024                 patt = 0;
<a name="l06025"></a>06025                 <span class="keywordflow">for</span> (iy = 0; iy &lt; charHeight; iy++) {
<a name="l06026"></a>06026                         mask = 0x00;
<a name="l06027"></a>06027                         curpos = linepos;
<a name="l06028"></a>06028                         <span class="keywordflow">for</span> (ix = 0; ix &lt; charWidth; ix++) {
<a name="l06029"></a>06029                                 <span class="keywordflow">if</span> (!(mask &gt;&gt;= 1)) {
<a name="l06030"></a>06030                                         patt = *charpos++;
<a name="l06031"></a>06031                                         mask = 0x80;
<a name="l06032"></a>06032                                 }
<a name="l06033"></a>06033 
<a name="l06034"></a>06034                                 <span class="keywordflow">if</span> (patt &amp; mask)
<a name="l06035"></a>06035                                         *(Uint32 *)curpos = color;
<a name="l06036"></a>06036                                 <span class="keywordflow">else</span>
<a name="l06037"></a>06037                                         *(Uint32 *)curpos = 0;
<a name="l06038"></a>06038                                 curpos += 4;
<a name="l06039"></a>06039                         }
<a name="l06040"></a>06040                         linepos += pitch;
<a name="l06041"></a>06041                 }
<a name="l06042"></a>06042 
<a name="l06043"></a>06043                 <span class="comment">/* Unlock font-surface */</span>
<a name="l06044"></a>06044                 SDL_UnlockSurface(gfxPrimitivesFont[ci]);
<a name="l06045"></a>06045 
<a name="l06046"></a>06046                 <span class="comment">/* Maybe rotate and replace cached image */</span>
<a name="l06047"></a>06047                 <span class="keywordflow">if</span> (charRotation&gt;0)
<a name="l06048"></a>06048                 {
<a name="l06049"></a>06049                         rotatedCharacter = <a class="code" href="_s_d_l__rotozoom_8c.html#a77563d68634cb2624d4f2f0bcdc19e73" title="Rotates a 32 bit surface in increments of 90 degrees.">rotateSurface90Degrees</a>(gfxPrimitivesFont[ci], charRotation);
<a name="l06050"></a>06050                         SDL_FreeSurface(gfxPrimitivesFont[ci]);
<a name="l06051"></a>06051                         gfxPrimitivesFont[ci] = rotatedCharacter;
<a name="l06052"></a>06052                 }
<a name="l06053"></a>06053         }
<a name="l06054"></a>06054 
<a name="l06055"></a>06055         <span class="comment">/*</span>
<a name="l06056"></a>06056 <span class="comment">        * Draw bitmap onto destination surface </span>
<a name="l06057"></a>06057 <span class="comment">        */</span>
<a name="l06058"></a>06058         result = SDL_BlitSurface(gfxPrimitivesFont[ci], &amp;srect, dst, &amp;drect);
<a name="l06059"></a>06059 
<a name="l06060"></a>06060         <span class="keywordflow">return</span> (result);
<a name="l06061"></a>06061 }
<a name="l06062"></a>06062 
<a name="l06077"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a3f2f624c33ca753d22db52a8d9363fac">06077</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a96379d2ce808aa642afb57bced0c670e" title="Draw a character of the currently set font.">characterRGBA</a>(SDL_Surface * dst, Sint16 x, Sint16 y, <span class="keywordtype">char</span> c, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l06078"></a>06078 {
<a name="l06079"></a>06079         <span class="comment">/*</span>
<a name="l06080"></a>06080 <span class="comment">        * Draw </span>
<a name="l06081"></a>06081 <span class="comment">        */</span>
<a name="l06082"></a>06082         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#aef5fdeb16c4578d8cd50e106299e993e" title="Draw a character of the currently set font.">characterColor</a>(dst, x, y, c, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a));
<a name="l06083"></a>06083 }
<a name="l06084"></a>06084 
<a name="l06099"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a96b6a43c6ef4753996e33bb7fea483bc">06099</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a62d2ba55abc7673f2dfa29e6bbffefdf" title="Draw a string in the currently set font.">stringColor</a>(SDL_Surface * dst, Sint16 x, Sint16 y, <span class="keyword">const</span> <span class="keywordtype">char</span> *s, Uint32 color)
<a name="l06100"></a>06100 {
<a name="l06101"></a>06101         <span class="keywordtype">int</span> result = 0;
<a name="l06102"></a>06102         Sint16 curx = x;
<a name="l06103"></a>06103         Sint16 cury = y;
<a name="l06104"></a>06104         <span class="keyword">const</span> <span class="keywordtype">char</span> *curchar = s;
<a name="l06105"></a>06105 
<a name="l06106"></a>06106         <span class="keywordflow">while</span> (*curchar &amp;&amp; !result) {
<a name="l06107"></a>06107                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#aef5fdeb16c4578d8cd50e106299e993e" title="Draw a character of the currently set font.">characterColor</a>(dst, curx, cury, *curchar, color);
<a name="l06108"></a>06108                 <span class="keywordflow">switch</span> (charRotation)
<a name="l06109"></a>06109                 {
<a name="l06110"></a>06110                 <span class="keywordflow">case</span> 0:
<a name="l06111"></a>06111                         curx += charWidthLocal;
<a name="l06112"></a>06112                         <span class="keywordflow">break</span>;
<a name="l06113"></a>06113                 <span class="keywordflow">case</span> 2:
<a name="l06114"></a>06114                         curx -= charWidthLocal;
<a name="l06115"></a>06115                         <span class="keywordflow">break</span>;
<a name="l06116"></a>06116                 <span class="keywordflow">case</span> 1:
<a name="l06117"></a>06117                         cury += charHeightLocal;
<a name="l06118"></a>06118                         <span class="keywordflow">break</span>;
<a name="l06119"></a>06119                 <span class="keywordflow">case</span> 3:
<a name="l06120"></a>06120                         cury -= charHeightLocal;
<a name="l06121"></a>06121                         <span class="keywordflow">break</span>;
<a name="l06122"></a>06122                 }
<a name="l06123"></a>06123                 curchar++;
<a name="l06124"></a>06124         }
<a name="l06125"></a>06125 
<a name="l06126"></a>06126         <span class="keywordflow">return</span> (result);
<a name="l06127"></a>06127 }
<a name="l06128"></a>06128 
<a name="l06143"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a769833ae414222099783a9b69bed4009">06143</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a6ca71826e311bdd9acf13b009256aa1c" title="Draw a string in the currently set font.">stringRGBA</a>(SDL_Surface * dst, Sint16 x, Sint16 y, <span class="keyword">const</span> <span class="keywordtype">char</span> *s, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l06144"></a>06144 {
<a name="l06145"></a>06145         <span class="comment">/*</span>
<a name="l06146"></a>06146 <span class="comment">        * Draw </span>
<a name="l06147"></a>06147 <span class="comment">        */</span>
<a name="l06148"></a>06148         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a62d2ba55abc7673f2dfa29e6bbffefdf" title="Draw a string in the currently set font.">stringColor</a>(dst, x, y, s, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a));
<a name="l06149"></a>06149 }
<a name="l06150"></a>06150 
<a name="l06151"></a>06151 <span class="comment">/* ---- Bezier curve */</span>
<a name="l06152"></a>06152 
<a name="l06162"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#a888411ec724ddb9ff19cf9ba9fc067df">06162</a> <span class="keywordtype">double</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a888411ec724ddb9ff19cf9ba9fc067df" title="Internal function to calculate bezier interpolator of data array with ndata values at position &#39;t&#39;...">_evaluateBezier</a> (<span class="keywordtype">double</span> *data, <span class="keywordtype">int</span> ndata, <span class="keywordtype">double</span> t) 
<a name="l06163"></a>06163 {
<a name="l06164"></a>06164         <span class="keywordtype">double</span> mu, result;
<a name="l06165"></a>06165         <span class="keywordtype">int</span> n,k,kn,nn,nkn;
<a name="l06166"></a>06166         <span class="keywordtype">double</span> blend,muk,munk;
<a name="l06167"></a>06167 
<a name="l06168"></a>06168         <span class="comment">/* Sanity check bounds */</span>
<a name="l06169"></a>06169         <span class="keywordflow">if</span> (t&lt;0.0) {
<a name="l06170"></a>06170                 <span class="keywordflow">return</span>(data[0]);
<a name="l06171"></a>06171         }
<a name="l06172"></a>06172         <span class="keywordflow">if</span> (t&gt;=(<span class="keywordtype">double</span>)ndata) {
<a name="l06173"></a>06173                 <span class="keywordflow">return</span>(data[ndata-1]);
<a name="l06174"></a>06174         }
<a name="l06175"></a>06175 
<a name="l06176"></a>06176         <span class="comment">/* Adjust t to the range 0.0 to 1.0 */</span> 
<a name="l06177"></a>06177         mu=t/(double)ndata;
<a name="l06178"></a>06178 
<a name="l06179"></a>06179         <span class="comment">/* Calculate interpolate */</span>
<a name="l06180"></a>06180         n=ndata-1;
<a name="l06181"></a>06181         result=0.0;
<a name="l06182"></a>06182         muk = 1;
<a name="l06183"></a>06183         munk = pow(1-mu,(<span class="keywordtype">double</span>)n);
<a name="l06184"></a>06184         <span class="keywordflow">for</span> (k=0;k&lt;=n;k++) {
<a name="l06185"></a>06185                 nn = n;
<a name="l06186"></a>06186                 kn = k;
<a name="l06187"></a>06187                 nkn = n - k;
<a name="l06188"></a>06188                 blend = muk * munk;
<a name="l06189"></a>06189                 muk *= mu;
<a name="l06190"></a>06190                 munk /= (1-mu);
<a name="l06191"></a>06191                 <span class="keywordflow">while</span> (nn &gt;= 1) {
<a name="l06192"></a>06192                         blend *= nn;
<a name="l06193"></a>06193                         nn--;
<a name="l06194"></a>06194                         <span class="keywordflow">if</span> (kn &gt; 1) {
<a name="l06195"></a>06195                                 blend /= (double)kn;
<a name="l06196"></a>06196                                 kn--;
<a name="l06197"></a>06197                         }
<a name="l06198"></a>06198                         <span class="keywordflow">if</span> (nkn &gt; 1) {
<a name="l06199"></a>06199                                 blend /= (double)nkn;
<a name="l06200"></a>06200                                 nkn--;
<a name="l06201"></a>06201                         }
<a name="l06202"></a>06202                 }
<a name="l06203"></a>06203                 result += data[k] * blend;
<a name="l06204"></a>06204         }
<a name="l06205"></a>06205 
<a name="l06206"></a>06206         <span class="keywordflow">return</span> (result);
<a name="l06207"></a>06207 }
<a name="l06208"></a>06208 
<a name="l06221"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#ad82395ca72b749494ff89be78f168341">06221</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#adfe8f9c42d29a090aae15eeb19b80d51" title="Draw a bezier curve with alpha blending.">bezierColor</a>(SDL_Surface * dst, <span class="keyword">const</span> Sint16 * vx, <span class="keyword">const</span> Sint16 * vy, <span class="keywordtype">int</span> n, <span class="keywordtype">int</span> s, Uint32 color)
<a name="l06222"></a>06222 {
<a name="l06223"></a>06223         <span class="keywordtype">int</span> result;
<a name="l06224"></a>06224         <span class="keywordtype">int</span> i;
<a name="l06225"></a>06225         <span class="keywordtype">double</span> *x, *y, t, stepsize;
<a name="l06226"></a>06226         Sint16 x1, y1, x2, y2;
<a name="l06227"></a>06227 
<a name="l06228"></a>06228         <span class="comment">/*</span>
<a name="l06229"></a>06229 <span class="comment">        * Sanity check </span>
<a name="l06230"></a>06230 <span class="comment">        */</span>
<a name="l06231"></a>06231         <span class="keywordflow">if</span> (n &lt; 3) {
<a name="l06232"></a>06232                 <span class="keywordflow">return</span> (-1);
<a name="l06233"></a>06233         }
<a name="l06234"></a>06234         <span class="keywordflow">if</span> (s &lt; 2) {
<a name="l06235"></a>06235                 <span class="keywordflow">return</span> (-1);
<a name="l06236"></a>06236         }
<a name="l06237"></a>06237 
<a name="l06238"></a>06238         <span class="comment">/*</span>
<a name="l06239"></a>06239 <span class="comment">        * Variable setup </span>
<a name="l06240"></a>06240 <span class="comment">        */</span>
<a name="l06241"></a>06241         stepsize=(double)1.0/(<span class="keywordtype">double</span>)s;
<a name="l06242"></a>06242 
<a name="l06243"></a>06243         <span class="comment">/* Transfer vertices into float arrays */</span>
<a name="l06244"></a>06244         <span class="keywordflow">if</span> ((x=(<span class="keywordtype">double</span> *)malloc(<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)*(n+1)))==NULL) {
<a name="l06245"></a>06245                 <span class="keywordflow">return</span>(-1);
<a name="l06246"></a>06246         }
<a name="l06247"></a>06247         <span class="keywordflow">if</span> ((y=(<span class="keywordtype">double</span> *)malloc(<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)*(n+1)))==NULL) {
<a name="l06248"></a>06248                 free(x);
<a name="l06249"></a>06249                 <span class="keywordflow">return</span>(-1);
<a name="l06250"></a>06250         }    
<a name="l06251"></a>06251         <span class="keywordflow">for</span> (i=0; i&lt;n; i++) {
<a name="l06252"></a>06252                 x[i]=(double)vx[i];
<a name="l06253"></a>06253                 y[i]=(double)vy[i];
<a name="l06254"></a>06254         }      
<a name="l06255"></a>06255         x[n]=(double)vx[0];
<a name="l06256"></a>06256         y[n]=(double)vy[0];
<a name="l06257"></a>06257 
<a name="l06258"></a>06258         <span class="comment">/*</span>
<a name="l06259"></a>06259 <span class="comment">        * Draw </span>
<a name="l06260"></a>06260 <span class="comment">        */</span>
<a name="l06261"></a>06261         result = 0;
<a name="l06262"></a>06262         t=0.0;
<a name="l06263"></a>06263         x1=(Sint16)lrint(<a class="code" href="_s_d_l__gfx_primitives_8c.html#a888411ec724ddb9ff19cf9ba9fc067df" title="Internal function to calculate bezier interpolator of data array with ndata values at position &#39;t&#39;...">_evaluateBezier</a>(x,n+1,t));
<a name="l06264"></a>06264         y1=(Sint16)lrint(<a class="code" href="_s_d_l__gfx_primitives_8c.html#a888411ec724ddb9ff19cf9ba9fc067df" title="Internal function to calculate bezier interpolator of data array with ndata values at position &#39;t&#39;...">_evaluateBezier</a>(y,n+1,t));
<a name="l06265"></a>06265         <span class="keywordflow">for</span> (i = 0; i &lt;= (n*s); i++) {
<a name="l06266"></a>06266                 t += stepsize;
<a name="l06267"></a>06267                 x2=(Sint16)<a class="code" href="_s_d_l__gfx_primitives_8c.html#a888411ec724ddb9ff19cf9ba9fc067df" title="Internal function to calculate bezier interpolator of data array with ndata values at position &#39;t&#39;...">_evaluateBezier</a>(x,n,t);
<a name="l06268"></a>06268                 y2=(Sint16)<a class="code" href="_s_d_l__gfx_primitives_8c.html#a888411ec724ddb9ff19cf9ba9fc067df" title="Internal function to calculate bezier interpolator of data array with ndata values at position &#39;t&#39;...">_evaluateBezier</a>(y,n,t);
<a name="l06269"></a>06269                 result |= <a class="code" href="_s_d_l__gfx_primitives_8c.html#ad44c550fab3cb736eb049713ede94052" title="Draw line with alpha blending.">lineColor</a>(dst, x1, y1, x2, y2, color);
<a name="l06270"></a>06270                 x1 = x2;
<a name="l06271"></a>06271                 y1 = y2;
<a name="l06272"></a>06272         }
<a name="l06273"></a>06273 
<a name="l06274"></a>06274         <span class="comment">/* Clean up temporary array */</span>
<a name="l06275"></a>06275         free(x);
<a name="l06276"></a>06276         free(y);
<a name="l06277"></a>06277 
<a name="l06278"></a>06278         <span class="keywordflow">return</span> (result);
<a name="l06279"></a>06279 }
<a name="l06280"></a>06280 
<a name="l06296"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a7203e3a463da499b5b0cadf211d19ff3">06296</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a4b7fbf6cc366abdf345a25308d53e125" title="Draw a bezier curve with alpha blending.">bezierRGBA</a>(SDL_Surface * dst, <span class="keyword">const</span> Sint16 * vx, <span class="keyword">const</span> Sint16 * vy, <span class="keywordtype">int</span> n, <span class="keywordtype">int</span> s, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l06297"></a>06297 {
<a name="l06298"></a>06298         <span class="comment">/*</span>
<a name="l06299"></a>06299 <span class="comment">        * Draw </span>
<a name="l06300"></a>06300 <span class="comment">        */</span>
<a name="l06301"></a>06301         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#adfe8f9c42d29a090aae15eeb19b80d51" title="Draw a bezier curve with alpha blending.">bezierColor</a>(dst, vx, vy, n, s, ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a));
<a name="l06302"></a>06302 }
<a name="l06303"></a>06303 
<a name="l06304"></a>06304 
<a name="l06323"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#af77127ff68a26c573dc5eb52723fb278">06323</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#af77127ff68a26c573dc5eb52723fb278" title="Internal function to initialize the Bresenham line iterator.">_bresenhamInitialize</a>(<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html" title="The structure passed to the internal Bresenham iterator.">SDL_gfxBresenhamIterator</a> *b, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2)
<a name="l06324"></a>06324 {
<a name="l06325"></a>06325         <span class="keywordtype">int</span> temp;
<a name="l06326"></a>06326 
<a name="l06327"></a>06327         <span class="keywordflow">if</span> (b==NULL) {
<a name="l06328"></a>06328                 <span class="keywordflow">return</span>(-1);
<a name="l06329"></a>06329         }
<a name="l06330"></a>06330 
<a name="l06331"></a>06331         b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#ae80d529920f12a3d3eda29b1a29e2e8a">x</a> = x1;
<a name="l06332"></a>06332         b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a48ddc054175e25d435c217ad4639c3a1">y</a> = y1;
<a name="l06333"></a>06333 
<a name="l06334"></a>06334         <span class="comment">/* dx = abs(x2-x1), s1 = sign(x2-x1) */</span>
<a name="l06335"></a>06335         <span class="keywordflow">if</span> ((b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a6a0d40b2ed6d9e674f93396212f0028f">dx</a> = x2 - x1) != 0) {
<a name="l06336"></a>06336                 <span class="keywordflow">if</span> (b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a6a0d40b2ed6d9e674f93396212f0028f">dx</a> &lt; 0) {
<a name="l06337"></a>06337                         b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a6a0d40b2ed6d9e674f93396212f0028f">dx</a> = -b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a6a0d40b2ed6d9e674f93396212f0028f">dx</a>;
<a name="l06338"></a>06338                         b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#acfb6b9e2b00e34da4313b463c341e597">s1</a> = -1;
<a name="l06339"></a>06339                 } <span class="keywordflow">else</span> {
<a name="l06340"></a>06340                         b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#acfb6b9e2b00e34da4313b463c341e597">s1</a> = 1;
<a name="l06341"></a>06341                 }
<a name="l06342"></a>06342         } <span class="keywordflow">else</span> {
<a name="l06343"></a>06343                 b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#acfb6b9e2b00e34da4313b463c341e597">s1</a> = 0;      
<a name="l06344"></a>06344         }
<a name="l06345"></a>06345 
<a name="l06346"></a>06346         <span class="comment">/* dy = abs(y2-y1), s2 = sign(y2-y1)    */</span>
<a name="l06347"></a>06347         <span class="keywordflow">if</span> ((b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a4817151aee120cc100c400d3076f4b93">dy</a> = y2 - y1) != 0) {
<a name="l06348"></a>06348                 <span class="keywordflow">if</span> (b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a4817151aee120cc100c400d3076f4b93">dy</a> &lt; 0) {
<a name="l06349"></a>06349                         b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a4817151aee120cc100c400d3076f4b93">dy</a> = -b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a4817151aee120cc100c400d3076f4b93">dy</a>;
<a name="l06350"></a>06350                         b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a4c68ffea7c3affb6a0ee6219aba89a69">s2</a> = -1;
<a name="l06351"></a>06351                 } <span class="keywordflow">else</span> {
<a name="l06352"></a>06352                         b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a4c68ffea7c3affb6a0ee6219aba89a69">s2</a> = 1;
<a name="l06353"></a>06353                 }
<a name="l06354"></a>06354         } <span class="keywordflow">else</span> {
<a name="l06355"></a>06355                 b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a4c68ffea7c3affb6a0ee6219aba89a69">s2</a> = 0;      
<a name="l06356"></a>06356         }
<a name="l06357"></a>06357 
<a name="l06358"></a>06358         <span class="keywordflow">if</span> (b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a4817151aee120cc100c400d3076f4b93">dy</a> &gt; b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a6a0d40b2ed6d9e674f93396212f0028f">dx</a>) {
<a name="l06359"></a>06359                 temp = b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a6a0d40b2ed6d9e674f93396212f0028f">dx</a>;
<a name="l06360"></a>06360                 b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a6a0d40b2ed6d9e674f93396212f0028f">dx</a> = b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a4817151aee120cc100c400d3076f4b93">dy</a>;
<a name="l06361"></a>06361                 b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a4817151aee120cc100c400d3076f4b93">dy</a> = temp;
<a name="l06362"></a>06362                 b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#ace147c79e29f2efd14e5744efcb976af">swapdir</a> = 1;
<a name="l06363"></a>06363         } <span class="keywordflow">else</span> {
<a name="l06364"></a>06364                 b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#ace147c79e29f2efd14e5744efcb976af">swapdir</a> = 0;
<a name="l06365"></a>06365         }
<a name="l06366"></a>06366 
<a name="l06367"></a>06367         b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a92fcd448f278df155fd5472527a6dc47">count</a> = (b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a6a0d40b2ed6d9e674f93396212f0028f">dx</a>&lt;0) ? 0 : (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a6a0d40b2ed6d9e674f93396212f0028f">dx</a>;
<a name="l06368"></a>06368         b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a4817151aee120cc100c400d3076f4b93">dy</a> &lt;&lt;= 1;
<a name="l06369"></a>06369         b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a11614f44ef4d939bdd984953346a7572">error</a> = b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a4817151aee120cc100c400d3076f4b93">dy</a> - b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a6a0d40b2ed6d9e674f93396212f0028f">dx</a>;
<a name="l06370"></a>06370         b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a6a0d40b2ed6d9e674f93396212f0028f">dx</a> &lt;&lt;= 1;    
<a name="l06371"></a>06371 
<a name="l06372"></a>06372         <span class="keywordflow">return</span>(0);
<a name="l06373"></a>06373 }
<a name="l06374"></a>06374 
<a name="l06375"></a>06375 
<a name="l06385"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#a4e0deda326a4dddde7adb2b20f927125">06385</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a4e0deda326a4dddde7adb2b20f927125" title="Internal function to move Bresenham line iterator to the next position.">_bresenhamIterate</a>(<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html" title="The structure passed to the internal Bresenham iterator.">SDL_gfxBresenhamIterator</a> *b)
<a name="l06386"></a>06386 {       
<a name="l06387"></a>06387         <span class="keywordflow">if</span> (b==NULL) {
<a name="l06388"></a>06388                 <span class="keywordflow">return</span> (-1);
<a name="l06389"></a>06389         }
<a name="l06390"></a>06390 
<a name="l06391"></a>06391         <span class="comment">/* last point check */</span>
<a name="l06392"></a>06392         <span class="keywordflow">if</span> (b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a92fcd448f278df155fd5472527a6dc47">count</a>==0) {
<a name="l06393"></a>06393                 <span class="keywordflow">return</span> (2);
<a name="l06394"></a>06394         }
<a name="l06395"></a>06395 
<a name="l06396"></a>06396         <span class="keywordflow">while</span> (b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a11614f44ef4d939bdd984953346a7572">error</a> &gt;= 0) {
<a name="l06397"></a>06397                 <span class="keywordflow">if</span> (b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#ace147c79e29f2efd14e5744efcb976af">swapdir</a>) {
<a name="l06398"></a>06398                         b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#ae80d529920f12a3d3eda29b1a29e2e8a">x</a> += b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#acfb6b9e2b00e34da4313b463c341e597">s1</a>;
<a name="l06399"></a>06399                 } <span class="keywordflow">else</span>  {
<a name="l06400"></a>06400                         b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a48ddc054175e25d435c217ad4639c3a1">y</a> += b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a4c68ffea7c3affb6a0ee6219aba89a69">s2</a>;
<a name="l06401"></a>06401                 }
<a name="l06402"></a>06402 
<a name="l06403"></a>06403                 b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a11614f44ef4d939bdd984953346a7572">error</a> -= b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a6a0d40b2ed6d9e674f93396212f0028f">dx</a>;
<a name="l06404"></a>06404         }
<a name="l06405"></a>06405 
<a name="l06406"></a>06406         <span class="keywordflow">if</span> (b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#ace147c79e29f2efd14e5744efcb976af">swapdir</a>) {
<a name="l06407"></a>06407                 b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a48ddc054175e25d435c217ad4639c3a1">y</a> += b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a4c68ffea7c3affb6a0ee6219aba89a69">s2</a>;
<a name="l06408"></a>06408         } <span class="keywordflow">else</span> {
<a name="l06409"></a>06409                 b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#ae80d529920f12a3d3eda29b1a29e2e8a">x</a> += b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#acfb6b9e2b00e34da4313b463c341e597">s1</a>;
<a name="l06410"></a>06410         }
<a name="l06411"></a>06411 
<a name="l06412"></a>06412         b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a11614f44ef4d939bdd984953346a7572">error</a> += b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a4817151aee120cc100c400d3076f4b93">dy</a>;      
<a name="l06413"></a>06413         b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a92fcd448f278df155fd5472527a6dc47">count</a>--;             
<a name="l06414"></a>06414 
<a name="l06415"></a>06415         <span class="comment">/* count==0 indicates &quot;end-of-line&quot; */</span>
<a name="l06416"></a>06416         <span class="keywordflow">return</span> ((b-&gt;<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a92fcd448f278df155fd5472527a6dc47">count</a>) ? 0 : 1);
<a name="l06417"></a>06417 }
<a name="l06418"></a>06418 
<a name="l06419"></a>06419 
<a name="l06428"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#ae11cad619c4fc85a7ff5d3c9d9686ccb">06428</a> <span class="keywordtype">void</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae11cad619c4fc85a7ff5d3c9d9686ccb" title="Internal function to to draw parallel lines with Murphy algorithm.">_murphyParaline</a>(<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html" title="The structure passed to the internal Murphy iterator.">SDL_gfxMurphyIterator</a> *m, Sint16 x, Sint16 y, <span class="keywordtype">int</span> d1)
<a name="l06429"></a>06429 {
<a name="l06430"></a>06430         <span class="keywordtype">int</span> p;
<a name="l06431"></a>06431         d1 = -d1;
<a name="l06432"></a>06432 
<a name="l06433"></a>06433         <span class="comment">/*</span>
<a name="l06434"></a>06434 <span class="comment">        * Lock the surface </span>
<a name="l06435"></a>06435 <span class="comment">        */</span>
<a name="l06436"></a>06436         <span class="keywordflow">if</span> (SDL_MUSTLOCK(m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af6547de04c77c00ed2d4597dd48ca807">dst</a>)) {
<a name="l06437"></a>06437                 SDL_LockSurface(m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af6547de04c77c00ed2d4597dd48ca807">dst</a>);
<a name="l06438"></a>06438         }
<a name="l06439"></a>06439 
<a name="l06440"></a>06440         <span class="keywordflow">for</span> (p = 0; p &lt;= m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a5874b4c2ec2e28321eea4e4871d08222">u</a>; p++) {
<a name="l06441"></a>06441 
<a name="l06442"></a>06442                 <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af6547de04c77c00ed2d4597dd48ca807">dst</a>, x, y, m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#afd133e412238ed9f1e3ba52397115e8d">color</a>);
<a name="l06443"></a>06443 
<a name="l06444"></a>06444                 <span class="keywordflow">if</span> (d1 &lt;= m-&gt;kt) {
<a name="l06445"></a>06445                         <span class="keywordflow">if</span> (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ab9894ea9f5570af0e7fa86e61a3bb60b">oct2</a> == 0) {
<a name="l06446"></a>06446                                 x++;
<a name="l06447"></a>06447                         } <span class="keywordflow">else</span> {
<a name="l06448"></a>06448                                 <span class="keywordflow">if</span> (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac65502ab7d0d8cbf739c6e06c35d8edb">quad4</a> == 0) {
<a name="l06449"></a>06449                                         y++;
<a name="l06450"></a>06450                                 } <span class="keywordflow">else</span> {
<a name="l06451"></a>06451                                         y--;
<a name="l06452"></a>06452                                 }
<a name="l06453"></a>06453                         }
<a name="l06454"></a>06454                         d1 += m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af59597daf52972ab61551495c3d7e6cd">kv</a>;
<a name="l06455"></a>06455                 } <span class="keywordflow">else</span> {        
<a name="l06456"></a>06456                         x++;
<a name="l06457"></a>06457                         <span class="keywordflow">if</span> (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac65502ab7d0d8cbf739c6e06c35d8edb">quad4</a> == 0) {
<a name="l06458"></a>06458                                 y++;
<a name="l06459"></a>06459                         } <span class="keywordflow">else</span> {
<a name="l06460"></a>06460                                 y--;
<a name="l06461"></a>06461                         }
<a name="l06462"></a>06462                         d1 += m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ade809c6ad2d8ae1dc2f665077951b81a">kd</a>;
<a name="l06463"></a>06463                 }
<a name="l06464"></a>06464         }
<a name="l06465"></a>06465 
<a name="l06466"></a>06466         <span class="comment">/* Unlock surface */</span>
<a name="l06467"></a>06467         <span class="keywordflow">if</span> (SDL_MUSTLOCK(m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af6547de04c77c00ed2d4597dd48ca807">dst</a>)) {
<a name="l06468"></a>06468                 SDL_UnlockSurface(m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af6547de04c77c00ed2d4597dd48ca807">dst</a>);
<a name="l06469"></a>06469         }
<a name="l06470"></a>06470 
<a name="l06471"></a>06471         m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af4320e1b2f9da1ee4155b6cfe35c8d7e">tempx</a> = x;
<a name="l06472"></a>06472         m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a4c3e88fc7abb5715d04e28d96a154e5f">tempy</a> = y;
<a name="l06473"></a>06473 }
<a name="l06474"></a>06474 
<a name="l06490"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#a9611a25f40d9cd4a70b3424dfa568b8b">06490</a> <span class="keywordtype">void</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a9611a25f40d9cd4a70b3424dfa568b8b" title="Internal function to to draw one iteration of the Murphy algorithm.">_murphyIteration</a>(<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html" title="The structure passed to the internal Murphy iterator.">SDL_gfxMurphyIterator</a> *m, Uint8 miter, 
<a name="l06491"></a>06491         Uint16 ml1bx, Uint16 ml1by, Uint16 ml2bx, Uint16 ml2by, 
<a name="l06492"></a>06492         Uint16 ml1x, Uint16 ml1y, Uint16 ml2x, Uint16 ml2y)
<a name="l06493"></a>06493 {
<a name="l06494"></a>06494         <span class="keywordtype">int</span> atemp1, atemp2;
<a name="l06495"></a>06495         <span class="keywordtype">int</span> ftmp1, ftmp2;
<a name="l06496"></a>06496         Uint16 m1x, m1y, m2x, m2y;      
<a name="l06497"></a>06497         Uint16 fix, fiy, lax, lay, curx, cury;
<a name="l06498"></a>06498         Uint16 px[4], py[4];
<a name="l06499"></a>06499         <a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html" title="The structure passed to the internal Bresenham iterator.">SDL_gfxBresenhamIterator</a> b;
<a name="l06500"></a>06500 
<a name="l06501"></a>06501         <span class="keywordflow">if</span> (miter &gt; 1) {
<a name="l06502"></a>06502                 <span class="keywordflow">if</span> (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a20a0f29217c4df1896f0b5b2e0db8901">first1x</a> != -32768) {
<a name="l06503"></a>06503                         fix = (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a20a0f29217c4df1896f0b5b2e0db8901">first1x</a> + m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a0043c9be4575c0c75cda25d9cec09deb">first2x</a>) / 2;
<a name="l06504"></a>06504                         fiy = (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a1e6adb477c4b1db15853adf1b5340760">first1y</a> + m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac8c0bb60c5be224d8d7fd4d4fd74930c">first2y</a>) / 2;
<a name="l06505"></a>06505                         lax = (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#adc37a4a286331a97587fdf4f239fa5e6">last1x</a> + m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a1acb203975c193230a03cee26bbd3f97">last2x</a>) / 2;
<a name="l06506"></a>06506                         lay = (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a48dabb55f39ba73ecacc558eba6f5b15">last1y</a> + m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ab85d5d3386d741c19de5bc0a7767d185">last2y</a>) / 2;
<a name="l06507"></a>06507                         curx = (ml1x + ml2x) / 2;
<a name="l06508"></a>06508                         cury = (ml1y + ml2y) / 2;
<a name="l06509"></a>06509 
<a name="l06510"></a>06510                         atemp1 = (fix - curx);
<a name="l06511"></a>06511                         atemp2 = (fiy - cury);
<a name="l06512"></a>06512                         ftmp1 = atemp1 * atemp1 + atemp2 * atemp2;
<a name="l06513"></a>06513                         atemp1 = (lax - curx);
<a name="l06514"></a>06514                         atemp2 = (lay - cury);
<a name="l06515"></a>06515                         ftmp2 = atemp1 * atemp1 + atemp2 * atemp2;
<a name="l06516"></a>06516 
<a name="l06517"></a>06517                         <span class="keywordflow">if</span> (ftmp1 &lt;= ftmp2) {
<a name="l06518"></a>06518                                 m1x = m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a20a0f29217c4df1896f0b5b2e0db8901">first1x</a>;
<a name="l06519"></a>06519                                 m1y = m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a1e6adb477c4b1db15853adf1b5340760">first1y</a>;
<a name="l06520"></a>06520                                 m2x = m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a0043c9be4575c0c75cda25d9cec09deb">first2x</a>;
<a name="l06521"></a>06521                                 m2y = m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac8c0bb60c5be224d8d7fd4d4fd74930c">first2y</a>;
<a name="l06522"></a>06522                         } <span class="keywordflow">else</span> {
<a name="l06523"></a>06523                                 m1x = m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#adc37a4a286331a97587fdf4f239fa5e6">last1x</a>;
<a name="l06524"></a>06524                                 m1y = m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a48dabb55f39ba73ecacc558eba6f5b15">last1y</a>;
<a name="l06525"></a>06525                                 m2x = m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a1acb203975c193230a03cee26bbd3f97">last2x</a>;
<a name="l06526"></a>06526                                 m2y = m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ab85d5d3386d741c19de5bc0a7767d185">last2y</a>;
<a name="l06527"></a>06527                         }
<a name="l06528"></a>06528 
<a name="l06529"></a>06529                         atemp1 = (m2x - ml2x);
<a name="l06530"></a>06530                         atemp2 = (m2y - ml2y);
<a name="l06531"></a>06531                         ftmp1 = atemp1 * atemp1 + atemp2 * atemp2;
<a name="l06532"></a>06532                         atemp1 = (m2x - ml2bx);
<a name="l06533"></a>06533                         atemp2 = (m2y - ml2by);
<a name="l06534"></a>06534                         ftmp2 = atemp1 * atemp1 + atemp2 * atemp2;
<a name="l06535"></a>06535 
<a name="l06536"></a>06536                         <span class="keywordflow">if</span> (ftmp2 &gt;= ftmp1) {
<a name="l06537"></a>06537                                 ftmp1 = ml2bx;
<a name="l06538"></a>06538                                 ftmp2 = ml2by;
<a name="l06539"></a>06539                                 ml2bx = ml2x;
<a name="l06540"></a>06540                                 ml2by = ml2y;
<a name="l06541"></a>06541                                 ml2x = ftmp1;
<a name="l06542"></a>06542                                 ml2y = ftmp2;
<a name="l06543"></a>06543                                 ftmp1 = ml1bx;
<a name="l06544"></a>06544                                 ftmp2 = ml1by;
<a name="l06545"></a>06545                                 ml1bx = ml1x;
<a name="l06546"></a>06546                                 ml1by = ml1y;
<a name="l06547"></a>06547                                 ml1x = ftmp1;
<a name="l06548"></a>06548                                 ml1y = ftmp2;
<a name="l06549"></a>06549                         }
<a name="l06550"></a>06550 
<a name="l06551"></a>06551                         <span class="comment">/*</span>
<a name="l06552"></a>06552 <span class="comment">                        * Lock the surface </span>
<a name="l06553"></a>06553 <span class="comment">                        */</span>
<a name="l06554"></a>06554                         <span class="keywordflow">if</span> (SDL_MUSTLOCK(m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af6547de04c77c00ed2d4597dd48ca807">dst</a>)) {
<a name="l06555"></a>06555                                 SDL_LockSurface(m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af6547de04c77c00ed2d4597dd48ca807">dst</a>);
<a name="l06556"></a>06556                         }
<a name="l06557"></a>06557 
<a name="l06558"></a>06558                         <a class="code" href="_s_d_l__gfx_primitives_8c.html#af77127ff68a26c573dc5eb52723fb278" title="Internal function to initialize the Bresenham line iterator.">_bresenhamInitialize</a>(&amp;b, m2x, m2y, m1x, m1y);
<a name="l06559"></a>06559                         <span class="keywordflow">do</span> {
<a name="l06560"></a>06560                                 <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af6547de04c77c00ed2d4597dd48ca807">dst</a>, b.<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#ae80d529920f12a3d3eda29b1a29e2e8a">x</a>, b.<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a48ddc054175e25d435c217ad4639c3a1">y</a>, m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#afd133e412238ed9f1e3ba52397115e8d">color</a>);
<a name="l06561"></a>06561                         } <span class="keywordflow">while</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a4e0deda326a4dddde7adb2b20f927125" title="Internal function to move Bresenham line iterator to the next position.">_bresenhamIterate</a>(&amp;b)==0);
<a name="l06562"></a>06562 
<a name="l06563"></a>06563                         <a class="code" href="_s_d_l__gfx_primitives_8c.html#af77127ff68a26c573dc5eb52723fb278" title="Internal function to initialize the Bresenham line iterator.">_bresenhamInitialize</a>(&amp;b, m1x, m1y, ml1bx, ml1by);
<a name="l06564"></a>06564                         <span class="keywordflow">do</span> {
<a name="l06565"></a>06565                                 <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af6547de04c77c00ed2d4597dd48ca807">dst</a>, b.<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#ae80d529920f12a3d3eda29b1a29e2e8a">x</a>, b.<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a48ddc054175e25d435c217ad4639c3a1">y</a>, m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#afd133e412238ed9f1e3ba52397115e8d">color</a>);
<a name="l06566"></a>06566                         } <span class="keywordflow">while</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a4e0deda326a4dddde7adb2b20f927125" title="Internal function to move Bresenham line iterator to the next position.">_bresenhamIterate</a>(&amp;b)==0);
<a name="l06567"></a>06567 
<a name="l06568"></a>06568                         <a class="code" href="_s_d_l__gfx_primitives_8c.html#af77127ff68a26c573dc5eb52723fb278" title="Internal function to initialize the Bresenham line iterator.">_bresenhamInitialize</a>(&amp;b, ml1bx, ml1by, ml2bx, ml2by);
<a name="l06569"></a>06569                         <span class="keywordflow">do</span> {
<a name="l06570"></a>06570                                 <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af6547de04c77c00ed2d4597dd48ca807">dst</a>, b.<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#ae80d529920f12a3d3eda29b1a29e2e8a">x</a>, b.<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a48ddc054175e25d435c217ad4639c3a1">y</a>, m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#afd133e412238ed9f1e3ba52397115e8d">color</a>);
<a name="l06571"></a>06571                         } <span class="keywordflow">while</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a4e0deda326a4dddde7adb2b20f927125" title="Internal function to move Bresenham line iterator to the next position.">_bresenhamIterate</a>(&amp;b)==0);
<a name="l06572"></a>06572 
<a name="l06573"></a>06573                         <a class="code" href="_s_d_l__gfx_primitives_8c.html#af77127ff68a26c573dc5eb52723fb278" title="Internal function to initialize the Bresenham line iterator.">_bresenhamInitialize</a>(&amp;b, ml2bx, ml2by, m2x, m2y);
<a name="l06574"></a>06574                         <span class="keywordflow">do</span> {
<a name="l06575"></a>06575                                 <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae94ba03884eee47c3bcc8e2fc35da9f0" title="Pixel draw with blending enabled if a&lt;255 - no surface locking.">pixelColorNolock</a>(m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af6547de04c77c00ed2d4597dd48ca807">dst</a>, b.<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#ae80d529920f12a3d3eda29b1a29e2e8a">x</a>, b.<a class="code" href="struct_s_d_l__gfx_bresenham_iterator.html#a48ddc054175e25d435c217ad4639c3a1">y</a>, m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#afd133e412238ed9f1e3ba52397115e8d">color</a>);
<a name="l06576"></a>06576                         } <span class="keywordflow">while</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a4e0deda326a4dddde7adb2b20f927125" title="Internal function to move Bresenham line iterator to the next position.">_bresenhamIterate</a>(&amp;b)==0);
<a name="l06577"></a>06577 
<a name="l06578"></a>06578                         <span class="comment">/* Unlock surface */</span>
<a name="l06579"></a>06579                         <span class="keywordflow">if</span> (SDL_MUSTLOCK(m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af6547de04c77c00ed2d4597dd48ca807">dst</a>)) {
<a name="l06580"></a>06580                                 SDL_UnlockSurface(m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af6547de04c77c00ed2d4597dd48ca807">dst</a>);
<a name="l06581"></a>06581                         }
<a name="l06582"></a>06582 
<a name="l06583"></a>06583                         px[0] = m1x;
<a name="l06584"></a>06584                         px[1] = m2x;
<a name="l06585"></a>06585                         px[2] = ml1bx;
<a name="l06586"></a>06586                         px[3] = ml2bx;
<a name="l06587"></a>06587                         py[0] = m1y;
<a name="l06588"></a>06588                         py[1] = m2y;
<a name="l06589"></a>06589                         py[2] = ml1by;
<a name="l06590"></a>06590                         py[3] = ml2by;                  
<a name="l06591"></a>06591                         <a class="code" href="_s_d_l__gfx_primitives_8c.html#a2d692dc25f3b579b386dff8dcd9cbc00" title="Draw polygon with alpha blending.">polygonColor</a>(m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af6547de04c77c00ed2d4597dd48ca807">dst</a>, px, py, 4, m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#afd133e412238ed9f1e3ba52397115e8d">color</a>);                                              
<a name="l06592"></a>06592                 }
<a name="l06593"></a>06593         }
<a name="l06594"></a>06594 
<a name="l06595"></a>06595         m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#adc37a4a286331a97587fdf4f239fa5e6">last1x</a> = ml1x;
<a name="l06596"></a>06596         m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a48dabb55f39ba73ecacc558eba6f5b15">last1y</a> = ml1y;
<a name="l06597"></a>06597         m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a1acb203975c193230a03cee26bbd3f97">last2x</a> = ml2x;
<a name="l06598"></a>06598         m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ab85d5d3386d741c19de5bc0a7767d185">last2y</a> = ml2y;
<a name="l06599"></a>06599         m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a20a0f29217c4df1896f0b5b2e0db8901">first1x</a> = ml1bx;
<a name="l06600"></a>06600         m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a1e6adb477c4b1db15853adf1b5340760">first1y</a> = ml1by;
<a name="l06601"></a>06601         m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a0043c9be4575c0c75cda25d9cec09deb">first2x</a> = ml2bx;
<a name="l06602"></a>06602         m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac8c0bb60c5be224d8d7fd4d4fd74930c">first2y</a> = ml2by;
<a name="l06603"></a>06603 }
<a name="l06604"></a>06604 
<a name="l06605"></a>06605 
<a name="l06606"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#a764ddb925da0921f024fadb4c12d7382">06606</a> <span class="preprocessor">#define HYPOT(x,y) sqrt((double)(x)*(double)(x)+(double)(y)*(double)(y)) </span>
<a name="l06607"></a>06607 <span class="preprocessor"></span>
<a name="l06622"></a><a class="code" href="_s_d_l__gfx_primitives_8c.html#abaa64d3d707ae122c88f2a509cded121">06622</a> <span class="keywordtype">void</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#abaa64d3d707ae122c88f2a509cded121" title="Internal function to to draw wide lines with Murphy algorithm.">_murphyWideline</a>(<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html" title="The structure passed to the internal Murphy iterator.">SDL_gfxMurphyIterator</a> *m, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 width, Uint8 miter)
<a name="l06623"></a>06623 {       
<a name="l06624"></a>06624         <span class="keywordtype">float</span> offset = (float)width / 2.f;
<a name="l06625"></a>06625 
<a name="l06626"></a>06626         Sint16 temp;
<a name="l06627"></a>06627         Sint16 ptx, pty, ptxx, ptxy, ml1x, ml1y, ml2x, ml2y, ml1bx, ml1by, ml2bx, ml2by;
<a name="l06628"></a>06628 
<a name="l06629"></a>06629         <span class="keywordtype">int</span> d0, d1;             <span class="comment">/* difference terms d0=perpendicular to line, d1=along line */</span>
<a name="l06630"></a>06630 
<a name="l06631"></a>06631         <span class="keywordtype">int</span> q;                  <span class="comment">/* pel counter,q=perpendicular to line */</span>
<a name="l06632"></a>06632         <span class="keywordtype">int</span> tmp;
<a name="l06633"></a>06633 
<a name="l06634"></a>06634         <span class="keywordtype">int</span> dd;                 <span class="comment">/* distance along line */</span>
<a name="l06635"></a>06635         <span class="keywordtype">int</span> tk;                 <span class="comment">/* thickness threshold */</span>
<a name="l06636"></a>06636         <span class="keywordtype">double</span> ang;             <span class="comment">/* angle for initial point calculation */</span>
<a name="l06637"></a>06637         <span class="keywordtype">double</span> sang, cang;
<a name="l06638"></a>06638 
<a name="l06639"></a>06639         <span class="comment">/* Initialisation */</span>
<a name="l06640"></a>06640         m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a5874b4c2ec2e28321eea4e4871d08222">u</a> = x2 - x1; <span class="comment">/* delta x */</span>
<a name="l06641"></a>06641         m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac8859e8c1ce357c4c8b37bbb1936ba1c">v</a> = y2 - y1; <span class="comment">/* delta y */</span>
<a name="l06642"></a>06642 
<a name="l06643"></a>06643         <span class="keywordflow">if</span> (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a5874b4c2ec2e28321eea4e4871d08222">u</a> &lt; 0) { <span class="comment">/* swap to make sure we are in quadrants 1 or 4 */</span>
<a name="l06644"></a>06644                 temp = x1;
<a name="l06645"></a>06645                 x1 = x2;
<a name="l06646"></a>06646                 x2 = temp;
<a name="l06647"></a>06647                 temp = y1;
<a name="l06648"></a>06648                 y1 = y2;
<a name="l06649"></a>06649                 y2 = temp;              
<a name="l06650"></a>06650                 m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a5874b4c2ec2e28321eea4e4871d08222">u</a> *= -1;
<a name="l06651"></a>06651                 m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac8859e8c1ce357c4c8b37bbb1936ba1c">v</a> *= -1;
<a name="l06652"></a>06652         }
<a name="l06653"></a>06653 
<a name="l06654"></a>06654         <span class="keywordflow">if</span> (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac8859e8c1ce357c4c8b37bbb1936ba1c">v</a> &lt; 0) { <span class="comment">/* swap to 1st quadrant and flag */</span>
<a name="l06655"></a>06655                 m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac8859e8c1ce357c4c8b37bbb1936ba1c">v</a> *= -1;
<a name="l06656"></a>06656                 m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac65502ab7d0d8cbf739c6e06c35d8edb">quad4</a> = 1;
<a name="l06657"></a>06657         } <span class="keywordflow">else</span> {
<a name="l06658"></a>06658                 m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac65502ab7d0d8cbf739c6e06c35d8edb">quad4</a> = 0;
<a name="l06659"></a>06659         }
<a name="l06660"></a>06660 
<a name="l06661"></a>06661         <span class="keywordflow">if</span> (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac8859e8c1ce357c4c8b37bbb1936ba1c">v</a> &gt; m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a5874b4c2ec2e28321eea4e4871d08222">u</a>) {      <span class="comment">/* swap things if in 2 octant */</span>
<a name="l06662"></a>06662                 tmp = m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a5874b4c2ec2e28321eea4e4871d08222">u</a>;
<a name="l06663"></a>06663                 m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a5874b4c2ec2e28321eea4e4871d08222">u</a> = m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac8859e8c1ce357c4c8b37bbb1936ba1c">v</a>;
<a name="l06664"></a>06664                 m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac8859e8c1ce357c4c8b37bbb1936ba1c">v</a> = tmp;
<a name="l06665"></a>06665                 m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ab9894ea9f5570af0e7fa86e61a3bb60b">oct2</a> = 1;
<a name="l06666"></a>06666         } <span class="keywordflow">else</span> {
<a name="l06667"></a>06667                 m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ab9894ea9f5570af0e7fa86e61a3bb60b">oct2</a> = 0;
<a name="l06668"></a>06668         }
<a name="l06669"></a>06669 
<a name="l06670"></a>06670         m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a2d8fc6210660a003e60ac96216cdd9d1">ku</a> = m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a5874b4c2ec2e28321eea4e4871d08222">u</a> + m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a5874b4c2ec2e28321eea4e4871d08222">u</a>;    <span class="comment">/* change in l for square shift */</span>
<a name="l06671"></a>06671         m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af59597daf52972ab61551495c3d7e6cd">kv</a> = m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac8859e8c1ce357c4c8b37bbb1936ba1c">v</a> + m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac8859e8c1ce357c4c8b37bbb1936ba1c">v</a>;    <span class="comment">/* change in d for square shift */</span>
<a name="l06672"></a>06672         m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ade809c6ad2d8ae1dc2f665077951b81a">kd</a> = m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af59597daf52972ab61551495c3d7e6cd">kv</a> - m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a2d8fc6210660a003e60ac96216cdd9d1">ku</a>;  <span class="comment">/* change in d for diagonal shift */</span>
<a name="l06673"></a>06673         m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac77eef4f813ec344cf850b89cc68818d">kt</a> = m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a5874b4c2ec2e28321eea4e4871d08222">u</a> - m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af59597daf52972ab61551495c3d7e6cd">kv</a>;   <span class="comment">/* diag/square decision threshold */</span>
<a name="l06674"></a>06674 
<a name="l06675"></a>06675         d0 = 0;
<a name="l06676"></a>06676         d1 = 0;
<a name="l06677"></a>06677         dd = 0;
<a name="l06678"></a>06678 
<a name="l06679"></a>06679         ang = atan((<span class="keywordtype">double</span>) m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac8859e8c1ce357c4c8b37bbb1936ba1c">v</a> / (<span class="keywordtype">double</span>) m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a5874b4c2ec2e28321eea4e4871d08222">u</a>);      <span class="comment">/* calc new initial point - offset both sides of ideal */</span>       
<a name="l06680"></a>06680         sang = sin(ang);
<a name="l06681"></a>06681         cang = cos(ang);
<a name="l06682"></a>06682 
<a name="l06683"></a>06683         <span class="keywordflow">if</span> (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ab9894ea9f5570af0e7fa86e61a3bb60b">oct2</a> == 0) {
<a name="l06684"></a>06684                 ptx = x1 + (Sint16)lrint(offset * sang);
<a name="l06685"></a>06685                 <span class="keywordflow">if</span> (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac65502ab7d0d8cbf739c6e06c35d8edb">quad4</a> == 0) {
<a name="l06686"></a>06686                         pty = y1 - (Sint16)lrint(offset * cang);
<a name="l06687"></a>06687                 } <span class="keywordflow">else</span> {
<a name="l06688"></a>06688                         pty = y1 + (Sint16)lrint(offset * cang);
<a name="l06689"></a>06689                 }
<a name="l06690"></a>06690         } <span class="keywordflow">else</span> {
<a name="l06691"></a>06691                 ptx = x1 - (Sint16)lrint(offset * cang);
<a name="l06692"></a>06692                 <span class="keywordflow">if</span> (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac65502ab7d0d8cbf739c6e06c35d8edb">quad4</a> == 0) {
<a name="l06693"></a>06693                         pty = y1 + (Sint16)lrint(offset * sang);
<a name="l06694"></a>06694                 } <span class="keywordflow">else</span> {
<a name="l06695"></a>06695                         pty = y1 - (Sint16)lrint(offset * sang);
<a name="l06696"></a>06696                 }
<a name="l06697"></a>06697         }
<a name="l06698"></a>06698 
<a name="l06699"></a>06699         <span class="comment">/* used here for constant thickness line */</span>
<a name="l06700"></a>06700         tk = (int) (4. * <a class="code" href="_s_d_l__gfx_primitives_8c.html#a764ddb925da0921f024fadb4c12d7382">HYPOT</a>(ptx - x1, pty - y1) * <a class="code" href="_s_d_l__gfx_primitives_8c.html#a764ddb925da0921f024fadb4c12d7382">HYPOT</a>(m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a5874b4c2ec2e28321eea4e4871d08222">u</a>, m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac8859e8c1ce357c4c8b37bbb1936ba1c">v</a>));
<a name="l06701"></a>06701 
<a name="l06702"></a>06702         <span class="keywordflow">if</span> (miter == 0) {
<a name="l06703"></a>06703                 m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a20a0f29217c4df1896f0b5b2e0db8901">first1x</a> = -32768;
<a name="l06704"></a>06704                 m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a1e6adb477c4b1db15853adf1b5340760">first1y</a> = -32768;
<a name="l06705"></a>06705                 m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a0043c9be4575c0c75cda25d9cec09deb">first2x</a> = -32768;
<a name="l06706"></a>06706                 m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac8c0bb60c5be224d8d7fd4d4fd74930c">first2y</a> = -32768;
<a name="l06707"></a>06707                 m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#adc37a4a286331a97587fdf4f239fa5e6">last1x</a> = -32768;
<a name="l06708"></a>06708                 m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a48dabb55f39ba73ecacc558eba6f5b15">last1y</a> = -32768;
<a name="l06709"></a>06709                 m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a1acb203975c193230a03cee26bbd3f97">last2x</a> = -32768;
<a name="l06710"></a>06710                 m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ab85d5d3386d741c19de5bc0a7767d185">last2y</a> = -32768;
<a name="l06711"></a>06711         }
<a name="l06712"></a>06712         ptxx = ptx;
<a name="l06713"></a>06713         ptxy = pty;
<a name="l06714"></a>06714 
<a name="l06715"></a>06715         <span class="keywordflow">for</span> (q = 0; dd &lt;= tk; q++) {    <span class="comment">/* outer loop, stepping perpendicular to line */</span>
<a name="l06716"></a>06716 
<a name="l06717"></a>06717                 <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae11cad619c4fc85a7ff5d3c9d9686ccb" title="Internal function to to draw parallel lines with Murphy algorithm.">_murphyParaline</a>(m, ptx, pty, d1);       <span class="comment">/* call to inner loop - right edge */</span>
<a name="l06718"></a>06718                 <span class="keywordflow">if</span> (q == 0) {
<a name="l06719"></a>06719                         ml1x = ptx;
<a name="l06720"></a>06720                         ml1y = pty;
<a name="l06721"></a>06721                         ml1bx = m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af4320e1b2f9da1ee4155b6cfe35c8d7e">tempx</a>;
<a name="l06722"></a>06722                         ml1by = m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a4c3e88fc7abb5715d04e28d96a154e5f">tempy</a>;
<a name="l06723"></a>06723                 } <span class="keywordflow">else</span> {
<a name="l06724"></a>06724                         ml2x = ptx;
<a name="l06725"></a>06725                         ml2y = pty;
<a name="l06726"></a>06726                         ml2bx = m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af4320e1b2f9da1ee4155b6cfe35c8d7e">tempx</a>;
<a name="l06727"></a>06727                         ml2by = m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a4c3e88fc7abb5715d04e28d96a154e5f">tempy</a>;
<a name="l06728"></a>06728                 }
<a name="l06729"></a>06729                 <span class="keywordflow">if</span> (d0 &lt; m-&gt;kt) {       <span class="comment">/* square move */</span>
<a name="l06730"></a>06730                         <span class="keywordflow">if</span> (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ab9894ea9f5570af0e7fa86e61a3bb60b">oct2</a> == 0) {
<a name="l06731"></a>06731                                 <span class="keywordflow">if</span> (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac65502ab7d0d8cbf739c6e06c35d8edb">quad4</a> == 0) {
<a name="l06732"></a>06732                                         pty++;
<a name="l06733"></a>06733                                 } <span class="keywordflow">else</span> {
<a name="l06734"></a>06734                                         pty--;
<a name="l06735"></a>06735                                 }
<a name="l06736"></a>06736                         } <span class="keywordflow">else</span> {
<a name="l06737"></a>06737                                 ptx++;
<a name="l06738"></a>06738                         }
<a name="l06739"></a>06739                 } <span class="keywordflow">else</span> {        <span class="comment">/* diagonal move */</span>
<a name="l06740"></a>06740                         dd += m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af59597daf52972ab61551495c3d7e6cd">kv</a>;
<a name="l06741"></a>06741                         d0 -= m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a2d8fc6210660a003e60ac96216cdd9d1">ku</a>;
<a name="l06742"></a>06742                         <span class="keywordflow">if</span> (d1 &lt; m-&gt;kt) {       <span class="comment">/* normal diagonal */</span>
<a name="l06743"></a>06743                                 <span class="keywordflow">if</span> (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ab9894ea9f5570af0e7fa86e61a3bb60b">oct2</a> == 0) {
<a name="l06744"></a>06744                                         ptx--;
<a name="l06745"></a>06745                                         <span class="keywordflow">if</span> (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac65502ab7d0d8cbf739c6e06c35d8edb">quad4</a> == 0) {
<a name="l06746"></a>06746                                                 pty++;
<a name="l06747"></a>06747                                         } <span class="keywordflow">else</span> {
<a name="l06748"></a>06748                                                 pty--;
<a name="l06749"></a>06749                                         }
<a name="l06750"></a>06750                                 } <span class="keywordflow">else</span> {
<a name="l06751"></a>06751                                         ptx++;
<a name="l06752"></a>06752                                         <span class="keywordflow">if</span> (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac65502ab7d0d8cbf739c6e06c35d8edb">quad4</a> == 0) {
<a name="l06753"></a>06753                                                 pty--;
<a name="l06754"></a>06754                                         } <span class="keywordflow">else</span> {
<a name="l06755"></a>06755                                                 pty++;
<a name="l06756"></a>06756                                         }
<a name="l06757"></a>06757                                 }
<a name="l06758"></a>06758                                 d1 += m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af59597daf52972ab61551495c3d7e6cd">kv</a>;
<a name="l06759"></a>06759                         } <span class="keywordflow">else</span> {        <span class="comment">/* double square move, extra parallel line */</span>
<a name="l06760"></a>06760                                 <span class="keywordflow">if</span> (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ab9894ea9f5570af0e7fa86e61a3bb60b">oct2</a> == 0) {
<a name="l06761"></a>06761                                         ptx--;
<a name="l06762"></a>06762                                 } <span class="keywordflow">else</span> {
<a name="l06763"></a>06763                                         <span class="keywordflow">if</span> (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac65502ab7d0d8cbf739c6e06c35d8edb">quad4</a> == 0) {
<a name="l06764"></a>06764                                                 pty--;
<a name="l06765"></a>06765                                         } <span class="keywordflow">else</span> {
<a name="l06766"></a>06766                                                 pty++;
<a name="l06767"></a>06767                                         }
<a name="l06768"></a>06768                                 }
<a name="l06769"></a>06769                                 d1 += m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ade809c6ad2d8ae1dc2f665077951b81a">kd</a>;
<a name="l06770"></a>06770                                 <span class="keywordflow">if</span> (dd &gt; tk) {
<a name="l06771"></a>06771                                         <a class="code" href="_s_d_l__gfx_primitives_8c.html#a9611a25f40d9cd4a70b3424dfa568b8b" title="Internal function to to draw one iteration of the Murphy algorithm.">_murphyIteration</a>(m, miter, ml1bx, ml1by, ml2bx, ml2by, ml1x, ml1y, ml2x, ml2y);
<a name="l06772"></a>06772                                         <span class="keywordflow">return</span>; <span class="comment">/* breakout on the extra line */</span>
<a name="l06773"></a>06773                                 }
<a name="l06774"></a>06774                                 <a class="code" href="_s_d_l__gfx_primitives_8c.html#ae11cad619c4fc85a7ff5d3c9d9686ccb" title="Internal function to to draw parallel lines with Murphy algorithm.">_murphyParaline</a>(m, ptx, pty, d1);
<a name="l06775"></a>06775                                 <span class="keywordflow">if</span> (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ab9894ea9f5570af0e7fa86e61a3bb60b">oct2</a> == 0) {
<a name="l06776"></a>06776                                         <span class="keywordflow">if</span> (m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#ac65502ab7d0d8cbf739c6e06c35d8edb">quad4</a> == 0) {
<a name="l06777"></a>06777                                                 pty++;
<a name="l06778"></a>06778                                         } <span class="keywordflow">else</span> {
<a name="l06779"></a>06779 
<a name="l06780"></a>06780                                                 pty--;
<a name="l06781"></a>06781                                         }
<a name="l06782"></a>06782                                 } <span class="keywordflow">else</span> {
<a name="l06783"></a>06783                                         ptx++;
<a name="l06784"></a>06784                                 }
<a name="l06785"></a>06785                         }
<a name="l06786"></a>06786                 }
<a name="l06787"></a>06787                 dd += m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#a2d8fc6210660a003e60ac96216cdd9d1">ku</a>;
<a name="l06788"></a>06788                 d0 += m-&gt;<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af59597daf52972ab61551495c3d7e6cd">kv</a>;
<a name="l06789"></a>06789         }
<a name="l06790"></a>06790 
<a name="l06791"></a>06791         <a class="code" href="_s_d_l__gfx_primitives_8c.html#a9611a25f40d9cd4a70b3424dfa568b8b" title="Internal function to to draw one iteration of the Murphy algorithm.">_murphyIteration</a>(m, miter, ml1bx, ml1by, ml2bx, ml2by, ml1x, ml1y, ml2x, ml2y);
<a name="l06792"></a>06792 }
<a name="l06793"></a>06793 
<a name="l06794"></a>06794 
<a name="l06808"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#a40c34464b6c99fd72c4bd7acfac5915d">06808</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a1494109358b4e4b7ec300d83e3f90300" title="Draw a thick line with alpha blending.">thickLineColor</a>(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 width, Uint32 color)
<a name="l06809"></a>06809 {       
<a name="l06810"></a>06810         <span class="keywordtype">int</span> wh;
<a name="l06811"></a>06811         <a class="code" href="struct_s_d_l__gfx_murphy_iterator.html" title="The structure passed to the internal Murphy iterator.">SDL_gfxMurphyIterator</a> m;
<a name="l06812"></a>06812 
<a name="l06813"></a>06813         <span class="keywordflow">if</span> (dst == NULL) <span class="keywordflow">return</span> -1;
<a name="l06814"></a>06814         <span class="keywordflow">if</span> (width &lt; 1) <span class="keywordflow">return</span> -1;
<a name="l06815"></a>06815 
<a name="l06816"></a>06816         <span class="comment">/* Special case: thick &quot;point&quot; */</span>
<a name="l06817"></a>06817         <span class="keywordflow">if</span> ((x1 == x2) &amp;&amp; (y1 == y2)) {
<a name="l06818"></a>06818                 wh = width / 2;
<a name="l06819"></a>06819                 <span class="keywordflow">return</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a6bb30dfc32d0aee20271a0356a2e2fd0" title="Draw box (filled rectangle) with blending.">boxColor</a>(dst, x1 - wh, y1 - wh, x2 + width, y2 + width, color);          
<a name="l06820"></a>06820         }
<a name="l06821"></a>06821 
<a name="l06822"></a>06822         m.<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#af6547de04c77c00ed2d4597dd48ca807">dst</a> = dst;
<a name="l06823"></a>06823         m.<a class="code" href="struct_s_d_l__gfx_murphy_iterator.html#afd133e412238ed9f1e3ba52397115e8d">color</a> = color;
<a name="l06824"></a>06824 
<a name="l06825"></a>06825         <a class="code" href="_s_d_l__gfx_primitives_8c.html#abaa64d3d707ae122c88f2a509cded121" title="Internal function to to draw wide lines with Murphy algorithm.">_murphyWideline</a>(&amp;m, x1, y1, x2, y2, width, 0);
<a name="l06826"></a>06826         <a class="code" href="_s_d_l__gfx_primitives_8c.html#abaa64d3d707ae122c88f2a509cded121" title="Internal function to to draw wide lines with Murphy algorithm.">_murphyWideline</a>(&amp;m, x1, y1, x2, y2, width, 1);
<a name="l06827"></a>06827 
<a name="l06828"></a>06828         <span class="keywordflow">return</span>(0);
<a name="l06829"></a>06829 }
<a name="l06830"></a>06830 
<a name="l06847"></a><a class="code" href="_s_d_l__gfx_primitives_8h.html#aa740c1eff9163862704eb3bb3b5964db">06847</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_primitives_8c.html#a8b24d64b51e23592c93abc2aa50c818e" title="Draw a thick line with alpha blending.">thickLineRGBA</a>(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 width, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
<a name="l06848"></a>06848 {
<a name="l06849"></a>06849         <span class="keywordflow">return</span> (<a class="code" href="_s_d_l__gfx_primitives_8c.html#a1494109358b4e4b7ec300d83e3f90300" title="Draw a thick line with alpha blending.">thickLineColor</a>(dst, x1, y1, x2, y2, width, 
<a name="l06850"></a>06850                 ((Uint32) r &lt;&lt; 24) | ((Uint32) g &lt;&lt; 16) | ((Uint32) b &lt;&lt; 8) | (Uint32) a));
<a name="l06851"></a>06851 }
</pre></div></div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.0
</small></address>

</body>
</html>
